#include <stdio.h>
#include <math.h>
void main ()
{
// x = The Input of sin(x)
// sine is the 'Total of sin (x)
//I - For-loop
float x,sine;
int I;
printf("Please Input The x Value");
scanf("f",&x);//Determind the user input
for(I=1; I<=x;)
sine= pow(1,1!);// here pow is red colour as well as !
printf("Sine Of %f = %f",x, sine);
}
n! translates to fac( n ). Note that C++ does not have a ! as a factorial operator. Nor does it have a factorial function in math.h. You'll have to write fac() yourself. Considering that it is the most common example program, I think you'll manage to write (find) it.
Now there are several ways to write this. The simplest one would be to have two for loops : one for adding and one for subtracting. The first would start from 1, the second - from 3. Both would increment by 4.
If you still don't understand something, ask specific questions. Also, you might want to read a tutorial..
When you do write this, you might want to notice that it is wasteful to recalculate the factorial and the power for each term. You know what the ratio of two consecutive terms is, so you can make this a lot faster.
//sin(x) = x^1/1! - X^3/3! + x^5/5! - x^7/7! + x^9/9!..
#include <stdio.h>
#include <math.h>
int fact(int x);
float sine(float x);
int main() // main is here
{ // Start of main block
int num;
float x,sine;
int I;
printf("Please Enter a Value For (x) Degree");
scanf("%d",&x);// degree
{
}
} // end of main block
int fact (int x)
float sine(float x)
{ // start of fact() block
// int = ans =1;
int ans = 1;
float sine;
int I,J,Q,K,num;
for (; x>1; x=x-1)
{
ans = ans *x;
}
float sine;
int I,J,Q,K;
for(I=1;I<=x;I+4)
for(J=3;J<=x;J+4)
Q= pow( x, I *fact(I));
K= pow( x, J *fact (J));
sine = pow( x, I )-pow( x, J );
sine ((param*PI/180);
printf("sine",&sine);
}
#include <stdio.h>
#include <math.h>
int fact(int x);
float sine(float x);
int main()
{
int num;
float x,sine;
int I;
printf("Please Enter a Value For (x) Degree");
scanf("%d",&x);
{//why is this here ?
//why isn't there anything here ?
}
}
int fact (int x)//here you say that you're starting fac() implementation
float sine(float x)//here you say that you're starting sine() implementation
{//so what does this one mean?
int ans = 1;
float sine;
int I,J,Q,K,num;
for (; x>1; x=x-1)
{
ans = ans *x;//this calculates a factorial ...
}
float sine; //so what is this part supposed to do ?
//why would you calculate sine in fac() function?
//also, you already declared sine above..
int I,J,Q,K;
for(I=1;I<=x;I+4)
for(J=3;J<=x;J+4)
Q= pow( x, I *fact(I));//this just overwrites Q a bunch of times
K= pow( x, J *fact (J));
sine = pow( x, I )-pow( x, J );
printf("sine",&sine);//this is supposed to be in main()
}
And your formatting is horrible.
This task seems to be too big for you. Start from the basics. Write a function fac() and a program that would calculate the factorial of user input. Again, you might want too look into some tutorial..
#include <stdio.h>
int fact(int x);
int main() // main is here
{ // Start of main block
int num;
printf("Please Enter a number");
scanf("%d",&num);
if(num<0){
printf(" No negative numbers, please.\n");
}
else
{
if (num>15)
{
printf( "Too large\n");
}
else
{
printf ("%d fact = %d\n",num, fact(num));
}
}
return 0;
}
int fact (int x)
{ // start of fact() block
// int = ans =1;
int ans = 1;
for (; x>1; x=x-1)
{
ans = ans *x;
}
return ans;
}
@Frozendog, now write a function which calculates the nth term in the sum. You know how to exponentate and how to find the factorial. Notice how constants change with n. If n starts from 0,
0 -> 1
1 -> 3
2 -> 5
3 -> 7
Also, note that terms are negative when n is odd. Your function will be double term(double x, int n);
@andywestken, he's having enough problems with the brute approach. I think it would be better if he did this first.