- #1
unscientific
- 1,734
- 13
Homework Statement
First of all, i wrote this code but i can't seem to get xcode to work on my mac and i'll only get to school in 2 days time, while this needs to be completed before school! I'm using xcode on Mac, programming language C.
Here's the question:
(a)Using a for loop, construct two 100 element arrays, x and y, such that element i of x stores the value sin(2∏i/100)) and the corresponding element of y stores cos((2∏i/100)). Print the values stored in the elements of x and y as you calculate them.
(b)Compute the scalar (i.e. dot) products x.x, y.y, and x.y, to check that sin and cos are orthogonal.
The Attempt at a Solution
(a)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
double x[100];
double y[100];
int i;
for ( i = 0; i <100; i++)
x = sin (2*M_PI*i/100);
y = sin (2*M_PI*i/100);
printf("%.3f \t %.3f \n ", x, y);
return 0;
}
(b)
/****/ I only did the first x.x part here, cause the others are pretty straightforward once I get this right..
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
double x[100];
double y[100];
double sumx;
double sumy;
int i;
for ( i = 0; i <100; i++)
x = sin (2*M_PI*i/100);
sumx = x*x;
y = sin (2*M_PI*i/100);
sumy = y*y;
printf("%.3f \t %.3f \n ", sumx, sumy);
return 0;
}