Calculate The Value Of This Sum Series [ S = 1 + 1/2 + 1/3 +...+ 1/N ]
Source code :-
#include<stdio.h>
int main()
{
int n;
float i=1.0,s=0.0;
printf("Enter the value of n: ");
scanf("%d",&n);
while(i<=n)
{
s=s+(i/(i+1));
i=i+1;
}
printf("Sum is => %.2f",s);
return 1;
}
Input-Output :-
abhi@hp-15q-laptop:~$ gcc s.c
abhi@hp-15q-laptop:~$ ./a.out
Enter the value of n: 5
Sum is => 3.55
إرسال تعليق