Tuesday, March 5, 2013

C PROGRAMS




Sine series

#include
#include
void main()
{
int i = 2, n, s = 1, x, pwr = 1, dr;
float nr = 1, x1, sum;
clrscr();
printf("\n\n\t ENTER THE ANGLE...: ");
scanf("%d", &x);
x1 = 3.142 * (x / 180.0);
sum = x1;
printf("\n\t ENTER THE NUMBER OF TERMS...: ");
scanf("%d", &n);
while(i <= n)
{
pwr = pwr + 2;
dr = dr * pwr * (pwr - 1);
sum = sum + (nr / dr) * s;
s = s * (-1);
nr = nr * x1 * x1;
i+= 2;
}
printf("\n\t THE SUM OF THE SINE SERIES IS..: %0.3f",sum);
getch();
}

Cosine series

#include<stdio.h>
#include<math.h>
void main()
{
float pow = 2.0, nr, dr = 1.0, x1, sum;
int i = 1,n,s = -1,x;
clrscr();
printf("\n\n\t ENTER THE ANGLE...: ");
scanf("%d", &x);
x1 = 3.142 * (x / 180.0);
sum = 1.0;
nr = x1*x1;
printf("\n\t ENTER THE NUMBER OF TERMS...: ");
scanf("%d",&n);
while(i<=n)
{
dr = dr * pow * (pow - 1.0);
sum = sum + (nr / (dr * s));
s = s * (-1);
pow = pow + 2.0;
nr = nr * x1 * x1;
i++;
}
printf("\n\t THE SUM OF THE COS SERIES IS..: %0.3f", sum);
getch();
}


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
main()
{
clrscr();
int x=1, y=2, counter;
float sum, number, n;
printf("Enter the value of n: ");
scanf("%f",&n);
for(counter=1;counter<=n;counter++)
{
number=(1/y);
sum=(x+number);
y++;
x=1/(++y);
printf("%f",sum);
}
return 0;
}

No comments: