Pages

Tuesday, 16 June 2015

Series 3

Number Series 3:
1+1/2+1/3+...+1/n


Coding:
#include<stdio.h>
int main()
{
int i,n;
float term,sum=0;
printf("Please enter the number of terms:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
term=1/(float)i;
sum=sum+term;
}
printf("Result is:%f",sum);
return 0;
}

Output:
Please enter the number of terms:5
Result is:2.283334