C program to find sum of series 1+1/2+1/3+1/4+1/5........+1/N - My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Monday, December 2, 2019

C program to find sum of series 1+1/2+1/3+1/4+1/5........+1/N - My CS Tutorial

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


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