We are hiring content writers to work from home

# A Program To Evaluate Sin(X) And Cos(X) Using Two Different Functions

Posted Date:     Total Responses: 0    Posted By: cihu   Member Level: Bronze   Points/Cash: 5

/* CALCULATING THE VALUE OF SIN(x) AND COS(x)USING FORMULA */

#include
#include
#include

float sin_x(float ,int );
float cos_x(float ,int );
float power(float ,int );
float fact (int);

void main()
{
int k=0,n;
float x;
clrscr();
printf("\n Enter the value of n:\t");
scanf("%d",&n);
printf("\n The table is\n\n x(in degree) sinx\t\t cosx\n");
printf(" -------------------------------------\n");

while(k<=90) /*The value of k is in degree*/
{
x=k;
x=(x*(4*atan(1)))/180;
printf(" %4d\t\t%0.4f\t\t%0.4f\n",k,sin_x(x,n),cos_x(x,n));
k+=15;
}
printf(" -------------------------------------\n");
getch();
}

float sin_x(float x,int n)
{
float sum=0,f;
int i;
for(i=1;i<=n;i++)
{
f=fact(2*i-1);
sum+=power(-1,i+1)*power(x,2*i-1)/f;
}
if(sum<0)
sum=-sum;
return(sum);
}
float cos_x(float x,int n)
{
int i;
float f,sum=0;
for(i=1;i<=n;i++)
{
f=fact(2*i-2);
sum+=power(-1,i+1)*power(x,2*i-2)/f;
}
if(sum<0)
sum=-sum;
return(sum);
}
float fact(int n)
{
if(n==0 || n==1)
return 1;
else
return n*fact(n-1);
}
float power(float x,int n)
{
int i;
float k;
k=x;
if(!n)
return (1);
else
{
for(i=1;i k=k*x;
return (k);
}
}

## Project Feedbacks

Author: Member Level: SilverRevenue Score:
this is awesome program,i try it and its work propely.

Post Feedback
Next Project: Food And Feeding Habits Of Three Fresh Water Fishes
Previous Project: A "C" in unix which creates a server and client environment

Related Projects

### Subscribe to Email

• Get Jobs by Email
• Forum posts by Email
• Articles by Email
Active Members
TodayLast 7 Days
more...