arrays - float x[N], f[N]; /* loop to fill other elements...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
/* arrays.c * Example code to define arrays containing N values of x between * MINX and MAXX, and the corresponding values of f(x)=sin(x)/x, * and to print the results to the screen. */ #include <stdio.h> #include <math.h> #define N 101 #define MINX -15.0 #define MAXX 15.0 float sinc(float xval); /* function prototype */ int main() { int i;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: float x[N], f[N]; /* loop to fill other elements */ for (i = 0; i &lt; N; i++) { x[i] = MINX + (MAXX - MINX)*i/(N - 1.0); f[i] = sinc(x[i]); } /* print values */ for (i = 0; i &lt; N; i++) printf(&quot;%f %f\n&quot;, x[i], f[i]); return 0; } float sinc(float xval) { if (xval == 0.0) return 1.0; else return sin(xval)/xval; }...
View Full Document

This note was uploaded on 09/29/2009 for the course COSC 1002 taught by Professor Wheatland during the Three '09 term at University of Sydney.

Ask a homework question - tutors are online