actually, I've made the program. but it still doesn't work well...the task is from my lecturer..
the task is about the function. after I enter the real number X and an integer number N. the program computes the value for Z, using factoring over N terms. the program also prints out the value of Z, cos(Z), and the N-th term. only use the function, not the pointer and the array..
Z = term 1 + term 2 + term 3...=1 - X^2/2! + X^4/4!...
here is my program...
=======================================================
/*INCLUDES*/
#include <stdio.h>
#include <math.h>
/*FUNCTION DECLARATIONS*/
long int Fac(long int);
double Term(long int, double);
int main()
{
double dCosx,dCosinus_x,dX;
long int liI;
printf("enter the X value : ");
scanf("%lf",&dX);
printf("enter the I value : ");
scanf("%li",&liI);
while (liI <= 0);
{
printf("give the positive value only!");
printf("enter I : ");
scanf("%li",&liI);
}
dCosx=Term(liI,dX);
dCosinus_x=cos(dX);
printf("\nCosx = %lf",dCosx);
printf("\nvalue of Cos (x) = %lf",dCosinus_x);
printf("\nX = %lf",dX);
return (0);
}
/*Term Function*/
double Term(long int liI, double dX)
{
double dRes, dA, dTotal, dRad;
int nRem, nCount;
dRad=dX;
nCount=0;
dTotal=0;
while(liI>nCount)
{
dA=pow(dRad,(2*nCount));
dRes=dA/Fac(2*nCount);
nRem=(nCount+2)%2;
if(nRem!=0);
{
dRes=dRes*-1;
}
nCount=nCount+1;
dTotal=dTotal + dRes;
}
printf("\nthe n-th Term is %lf",&dRes);
return (dTotal);
}
/*Factorial Function*/
long int Fac(long int liI)
{
long int liFactorial;
if (liI == 0)
{
liFactorial = 1;
}
else
{
liFactorial = liI*Fac(liI-1);
}
return (liFactorial);
}
================================================
some body can help me, please?
the task is about the function. after I enter the real number X and an integer number N. the program computes the value for Z, using factoring over N terms. the program also prints out the value of Z, cos(Z), and the N-th term. only use the function, not the pointer and the array..
Z = term 1 + term 2 + term 3...=1 - X^2/2! + X^4/4!...
here is my program...
=======================================================
/*INCLUDES*/
#include <stdio.h>
#include <math.h>
/*FUNCTION DECLARATIONS*/
long int Fac(long int);
double Term(long int, double);
int main()
{
double dCosx,dCosinus_x,dX;
long int liI;
printf("enter the X value : ");
scanf("%lf",&dX);
printf("enter the I value : ");
scanf("%li",&liI);
while (liI <= 0);
{
printf("give the positive value only!");
printf("enter I : ");
scanf("%li",&liI);
}
dCosx=Term(liI,dX);
dCosinus_x=cos(dX);
printf("\nCosx = %lf",dCosx);
printf("\nvalue of Cos (x) = %lf",dCosinus_x);
printf("\nX = %lf",dX);
return (0);
}
/*Term Function*/
double Term(long int liI, double dX)
{
double dRes, dA, dTotal, dRad;
int nRem, nCount;
dRad=dX;
nCount=0;
dTotal=0;
while(liI>nCount)
{
dA=pow(dRad,(2*nCount));
dRes=dA/Fac(2*nCount);
nRem=(nCount+2)%2;
if(nRem!=0);
{
dRes=dRes*-1;
}
nCount=nCount+1;
dTotal=dTotal + dRes;
}
printf("\nthe n-th Term is %lf",&dRes);
return (dTotal);
}
/*Factorial Function*/
long int Fac(long int liI)
{
long int liFactorial;
if (liI == 0)
{
liFactorial = 1;
}
else
{
liFactorial = liI*Fac(liI-1);
}
return (liFactorial);
}
================================================
some body can help me, please?