Write a programme for estimation of the S value = n i=1 ∑ 1/ (ki) 2 + 1
Note: n as integer value and element values of k as float type should be taken from users
Sometimes when I give n the value 8 or a different value it asks for more than n values for k
my code:
#include <stdio.h>
int main()
{
int i,n;
float k,total;
printf("enter a value for n: ");
scanf("%d",&n);
total=0;
for(i=1;i<=n;i++)
{
for(k=i;k<=i;k++)
{
printf("enter values for k:");
scanf("%f",&k);
total=total+1/(k*k+1);
}
}
printf("result = %f\n",total);
return 0;
}
Last edited: