Problem Statement
Write a c program to calculate the sum of the series
1+(1/2)+(1/3)...+(1/n)
you should take the value of n as an input from the user
#include<stdio.h>
int main()
{
float sum,i,n;
printf("enter the value of n:\n");
scanf("%f",&n);
sum=0.0;
for(i=1.0;i<n+1;i++)
{
sum=sum+(1/i);
}
printf("the sum is equal to :%f",sum);
return 0;
}
Write a c program to calculate the sum of the series
1+(1/2)+(1/3)...+(1/n)
you should take the value of n as an input from the user
#include<stdio.h>
int main()
{
float sum,i,n;
printf("enter the value of n:\n");
scanf("%f",&n);
sum=0.0;
for(i=1.0;i<n+1;i++)
{
sum=sum+(1/i);
}
printf("the sum is equal to :%f",sum);
return 0;
}
No comments:
Post a Comment