[My site ]
Main » 2013 » December » 13 » 2010-2011 question 5
0:01 AM
2010-2011 question 5
write a program to add n terms of the following series :
y = 1 - 2/3^2 + 3/5^2 - 4/7^2 +5/9^2 - .......

#include"stdio.h"
float com(float x);
main()
{
int i, n;
float y=0, k, j;
printf("enter number of terms : ");
scanf("%d", &n);
for(i=1;i<=n;i++){
j=i; /* j float , i int */
if(i%2==0){
y-=com(j);
}else{
y+=com(j);
}
}
printf("Y = %0.2f", y);
getch();
return 0;
}

float com(float x)
{
float co1, co2;
co2= 4*x*x-4*x+1; /* (2x-1)^2 */
co1= x/co2;
return co1;
}
Category: C Programming - 1 | Views: 411 | Added by: ahansaary | Rating: 0.0/0
Total comments: 0
Only registered users can add comments.
[ Sign Up | Login ]