I have an assignment im working on for my computer science class (c programming). My program compiles right, but doesn't run like its suppose to. Could someone help me?
Here is the assignment:
The value of sin(x) can be approximated by using the formula:
sin(x) = x −x3/3!+x5/5!−x7/7!+x9/9!· · ·
where x is an angle in radians. Using the formula, approximate the value of the
sine of an angle (in degrees) entered by the user by calculating the first 15 terms of the series. The program should allow the user to repeatedly enter angles and then display the sine, until the value 0 is entered. Here is the general outline for the program:
1 read in a new value for angle
2 while(angle != 0){
3 convert angle to radians (multiply angle by pi/ 180 )
4 sine = 0
5 n = 1
6 while(n ≤ 15) {
7 calculate next term of series and add it to/subtract it from sine
8 increment n
9 }
10 display sine
11 read in a new value for angle
12 }
Here is an example run of the program:
Enter an angle in degrees (0 quits): 30
sin(30) = 0.5
Enter an angle in degrees (0 quits): 45
sin(45) = 0.707106
Enter an angle in degrees (0 quits): 90
sin(30) = 1
Enter an angle in degrees (0 quits): 15
sin(30) = 0.258819
Enter an angle in degrees (0 quits): 60
sin(30) = 0.866025
Enter an angle in degrees (0 quits): 0
Hint: to get the value of pi, you must have the following statement at the
begining of your code:
#define PI 3.1415926535897 93
save as sine.c
Here is what i wrote:
[CODE=c]#include<math.h >
#include<stdio. h>
#define PI 3.1415926535897 93
int main()
{
double angle,radian,si ne,n,x,factoria l,s,i;
x = 1;
printf("Enter angle in degrees (0 to quit)\n");
scanf("%f",&ang le);
for (i=1;i<=15;i++) {
factorial=facto rial*n;
while (angle!=0){
radian=angle*(P I/180);
sine=0;
n=1;
while (n<=15)
{
s = (radian - ( pow(radian, n) ) / (factorial));
n++;
}
printf("sin(%f) =%f\n",angle,s) ;
printf("Enter angle in degrees (0 to quit): ");
scanf("%f",&ang le);
}
}
return 0;
}[/CODE]
Here is the assignment:
The value of sin(x) can be approximated by using the formula:
sin(x) = x −x3/3!+x5/5!−x7/7!+x9/9!· · ·
where x is an angle in radians. Using the formula, approximate the value of the
sine of an angle (in degrees) entered by the user by calculating the first 15 terms of the series. The program should allow the user to repeatedly enter angles and then display the sine, until the value 0 is entered. Here is the general outline for the program:
1 read in a new value for angle
2 while(angle != 0){
3 convert angle to radians (multiply angle by pi/ 180 )
4 sine = 0
5 n = 1
6 while(n ≤ 15) {
7 calculate next term of series and add it to/subtract it from sine
8 increment n
9 }
10 display sine
11 read in a new value for angle
12 }
Here is an example run of the program:
Enter an angle in degrees (0 quits): 30
sin(30) = 0.5
Enter an angle in degrees (0 quits): 45
sin(45) = 0.707106
Enter an angle in degrees (0 quits): 90
sin(30) = 1
Enter an angle in degrees (0 quits): 15
sin(30) = 0.258819
Enter an angle in degrees (0 quits): 60
sin(30) = 0.866025
Enter an angle in degrees (0 quits): 0
Hint: to get the value of pi, you must have the following statement at the
begining of your code:
#define PI 3.1415926535897 93
save as sine.c
Here is what i wrote:
[CODE=c]#include<math.h >
#include<stdio. h>
#define PI 3.1415926535897 93
int main()
{
double angle,radian,si ne,n,x,factoria l,s,i;
x = 1;
printf("Enter angle in degrees (0 to quit)\n");
scanf("%f",&ang le);
for (i=1;i<=15;i++) {
factorial=facto rial*n;
while (angle!=0){
radian=angle*(P I/180);
sine=0;
n=1;
while (n<=15)
{
s = (radian - ( pow(radian, n) ) / (factorial));
n++;
}
printf("sin(%f) =%f\n",angle,s) ;
printf("Enter angle in degrees (0 to quit): ");
scanf("%f",&ang le);
}
}
return 0;
}[/CODE]
Comment