Hi, I have just begun to learn C and I have come across the following question:
Using a for loop, construct two 100 element arrays, x and y, such that element i of x stores the value sin(2*pi*i/100)) and the corresponding element of y stores cos((2*pi*i/100)). Print the values stored in the elements of x and y as you calculate them.
I have attempted to solve it but I'm not sure why the value 0 is only being printed, maybe I haven't assigned sin(2i/100)) and cos((2i/100)) to the arrays properly?
Here is my attempt at the solution:
ThanksCode:#include<stdio.h> #include<stdlib.h> #include<math.h> int main () { /*Define arrays*/ int x[100]; int y[100]; int i; /* For loops for x and y using i*/ for (i=0; i<100; i++) { x[i] = sin (((2.0*M_PI)*i)/100.0); y[i] = cos (((2.0*M_PI)*i)/100.0); printf(" Value of x %d: %d\n", i, x[i]); printf(" Value of y %d: %d\n", i, y[i]); } return(0); }