English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories
0

this program not work

/* e(x) = 1 + x + x2 / 2! + x3 / 3! + x4/ 4! --------- xn / n! */
#include
#include
#include
void main()
{
int fact();
float x, t, sum;
int i, n;
printf("\n Enter the Value of x & n:");
scanf("%f %d", &x, &n);
x = x * 3.14/180;
t = 1;
sum = 1;
for ( i = 1; i <= n; i++)
{
t = t * pow(x, i) / fact(i);
sum = sum + t;
}
printf("\n The Value of ex = %f \n", sum);
}
int fact( int n)
{
int i;
for ( i = 1; i <= n; i++)
fact *= i; // this line error is found pls correct it
return fact;
}

2007-06-28 20:21:34 · 3 answers · asked by robin j 1 in Computers & Internet Programming & Design

3 answers

fact() is a function that returns an integer.
The error line is using fact as a variable. This variable has not been defined or initialised.

2007-06-28 20:40:56 · answer #1 · answered by AnalProgrammer 7 · 0 0

Let me put it in a simple way: you probably got your own math right but the syntax is wrong, three times as a matter of fact, they are all related to how fact() should be written and used.

#include
#include
#include
int fact(int);
void main()
{
// int fact(); this goes up and incorrectly written
float x, t, sum;
int i, n;
printf("\n Enter the Value of x & n:");
scanf("%f %d", &x, &n);
x = x * 3.14/180;
t = 1;
sum = 1;
for ( i = 1; i <= n; i++)
{
t = t * pow(x, i) / fact(i);
sum = sum + t;
}
printf("\n The Value of ex = %f \n", sum);
}
int fact( int n)
{
int i, answer = 1; // here
for ( i = 1; i <= n; i++)
answer *= i; // this line error is found pls correct it
return answer;
}

2007-06-29 04:06:52 · answer #2 · answered by Andy T 7 · 0 0

There are too many problems, Contact a freelance programmer to help you learn the language fast. Check http://getafreelnacer.com/

2007-06-29 07:00:29 · answer #3 · answered by easymf co in 3 · 0 0

fedest.com, questions and answers