# Beginner at C! help...Array problem

This is a discussion on Beginner at C! help...Array problem within the C Programming forums, part of the General Programming Boards category; 'using a for loop, construct two 100 element arrays, x,y such that i of x stores the value sin(2*pi*i/100) and ...

1. ## Beginner at C! help...Array problem

'using a for loop, construct two 100 element arrays, x,y such that i of x stores the value sin(2*pi*i/100) and corresponding for y cos(''' ')print the values stored in elements of x,y as you calculate..'

cant see where im wrong?

Many thanks!!!!

insert
Code:
```#include <stdio.h>
#include <stlib.h>
#define PI 3.142

int main()

{
//stating variable type and titles of the arrays

int i, x[100], y[100];

for(i=0; i<=100; i++)

x[i]=sin((2*PI*i)/100)); //in general for every element
y[i]=cos((2*PI*i)/100));

printf("%.2f\t %.2f\n",x[i],y[i]);

scanf("d\n");

exit(0);
}```

2. Okay well heres some corrections:
Code:
```#include <stdio.h>
#include <stdlib.h>
#include <math.h> // Need to include math.h for sin and cos
#define PI 3.142

int main()
{
//stating variable type and titles of the arrays
int i;
float x[100], y[100]; // X and Y should be floats of doubles
for(i=0; i<=100; i++)
{
x[i]=sin((2*PI*i)/100); //brackets dident match here.
y[i]=cos((2*PI*i)/100);
printf("&#37;.2f\t %.2f\n",x[i],y[i]);
}
getchar();
exit(0);
}```
Edit: oh and you might want to get into the habit of indenting as it makes your code much more readable

why must x y be floats of doubles?

why not floats of floats?

4. Np

you need to use a float or double to store numbers with fractions. Either will do but doubles give better precision. Sin and cos return numbers between -1 and 1 so using integers all numbers would end up being -1, 0, or 1.

Also, technically, not that it matters too much here, but sin is meant to be for y, and cos for x.

5. Okay..thanks!

This question develops: "compute the dot products of x.x,, y.y, x.y checking that sinx and cosx are orthogonal..x.y=sum(x.y) "

I am really stuck here. Maybe that is my maths. My attempt is as pitifully follows:

include
Code:
```#include <stdio.h>
#include <stlib.h>
#define PI 3.142

int main()

{
//stating variable type and titles of the arrays
int i;
float ,sinC, x[36], y[36], sumsq, sumsr, sumss;

for(i=0; i<=360; i++)
{

x[i]*y[i]= sin
y[i]*y[i]=

//shall i define the arrays? or the mulitiplied arrays?

x.y=absinc?

sumsq=x[i]*x[i]
sumsr=y[i]*y[i]
sumss=x[i]*y[i]

printf("&#37;.2f\t %.2f% %.2f\n",sumq, sumsr, sumss);
}

scanf("d\n");

exit(0);
}```

6. I would like you to remember that everything within the block { and } is part of the parent statement, in this case the for. This was your problem in your last post.
And your indentation is not very good. You are going to get into troubles with poor indentation. I recommend you read this.