-
Am I missing something?
I want to print a trigonometric table for sin, cos, and tan.
Code:
#include<stdio.h>
#include<math.h>
/*
* Main Function
*/
int main(void)
{
double two_pi = 2.0 * M_PI;
double interval = two_pi / 19;
double number;
printf("Number, sin(), cos(), tan()");
{
("%lf%lf%lf%lf/n",number, sin(number), cos(number), tan(number));
for(number=0;number <= two_pi;number +=interval);
}
return 0;
}
-
Uh, yeah. What the hell is this?
Code:
printf("Number, sin(), cos(), tan()");
{
("%lf%lf%lf%lf/n",number, sin(number), cos(number), tan(number));
for(number=0;number <= two_pi;number +=interval);
}
Or is that a REALLY bad copy/paste fail?
-
update
Sorry this is the one that was on the actual program. I just typed that from my notebook while I was waiting for the program to run. It isn't much different. I just need it to do the increments....
Code:
#include<stdio.h>
#include<math.h>
int main(void)
{
double two_pi = 2.0 * M_PI;
double interval = two_pi / 19;
double number;
printf("\nNumber Sin( ) Cos( ) Tan( ) \n");
scanf("%lf %lf %lf %lf\n", &number, &sin(number), &cos(number), &tan(number));
{
for(number=0;number <= two_pi;number +=interval);
}
return 0;
}
-
That is still bad. The opening brace before the for loop should be after.
-
so I have gotten this far...now with the incrementing? is there a tutorial that I can use?
Code:
int main(void)
{
double two_pi = 2.0 * M_PI;
double interval = two_pi / 19;
double number;
printf("\nNumber Sin( ) Cos( ) Tan( ) \n");
for(number=0;number <= two_pi;number +=interval);
{
printf("%lf %lf %lf %lf\n",number, sin(number), cos(number), tan(number));
}
return 0;
}
-
No semicolon at the end here:
Code:
for(number=0;number <= two_pi;number +=interval);
Also, comparing doubles is fraught with danger, due to the imprecision of floating point mathematics.
-
hmmm...
Now why did that semicolon stop my entire table from printing? (it worked by the way! Thanks)
-
A for statement is ended by the semi-colon. An early one just short-circuits all the printing code.
-
Code:
#include<stdio.h>
#include<math.h>
/*
* Main Function
*/
int main(void)
{
double two_pi = 2.0 * M_PI;
double interval = two_pi / 19;
double number;
for (number = 0; number < two_pi; number += interval)
printf("%lf || %lf || %lf% || %lf\n",number, sin(number), cos(number), tan(number));
return 0;
}
there were quite some problems in the code like
for statement was not correct syntax is
for( intialize ; condition ; inc/dec) {}
printf(); was not there and even syntax was not correct new line character is like this \n not /n this way
you can not put like this printf() {
}