Write a program to print the sum of 1+1/sqr(2)+1/sqr(3)+….

#include<conio.h>
#include<stdio.h>
#include<math.h>
int main()
{
int terms,i=1;
float ans=0.0;
printf("Enter number of terms");
scanf("%d",&terms);
while(i<=terms)
{
ans=ans+(float) 1/pow(i,2);
i++;
}
printf("\nThe ans is %f",ans);
}

No comments:

Post a Comment