Brijmohan lal Sahu - Facebook
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Saturday, December 6, 2014

Program to calculate sum of series using for loop in C.





Code Box
---------------------------------------------

/*Program to calculate sum of series

 1/1+1/2+1/3+.......+1/n

 where n is the value entered by user.

 =>Explicit type conversion

*/

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,n;
float sum;
clrscr();
sum=0;

printf("\nEnter limit number : ");
scanf("%d",&n);


printf("\nSeries=");

printf("\n---------------------\n");

for(i=1;i<=n;i++)
{

printf(" +1/%d ",i);
sum=sum+(float)1/i; //Explicit type conversion

}

printf("\n---------------------\n");

printf("\nSum of series= %.3f",sum);

getch();
}





No comments: