In this tutorial we will learn how to write a program that print the sum of a series.If the series is...
1+1/2+1/3+1/4+1/5........+1/N
In this output the value of number(range) is 7
The series is
1+1/2+1/3+1/4+1/5+1/6+1/7
And the sum of this series is 2.592857
1+1/2+1/3+1/4+1/5........+1/N
C program code
#include<stdio.h>
#include<conio.h>
void main()
{
int a,num;
float sum=0;
printf("\n Enter the range of series:\n ");
scanf("%d",&num);
for(a=1;a<=num;a++)
{
sum+=(float)1/a;
}
printf("\n The value of series:\n ");
for(a=1;a<=num;a++)
{
if(a<num)
{
printf("1/%d + ",a);
}
else
{
printf("1/%d = ",a);
}
}
printf("%f\n",sum);
getch();
}
OUTPUT:
In this output the value of number(range) is 7
The series is
1+1/2+1/3+1/4+1/5+1/6+1/7
And the sum of this series is 2.592857
Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.
Created by-- HARSH CHAUHAN
No comments:
Post a Comment