/*
Summary: Print sum of series
1 + 1/2 + 1/3 + 1/4 + ... + 1/N.
*/
#include<stdio.h>
#include<conio.h>
int main()
{
double n,sum=0,i;
clrscr();
printf("\n Please Give The Value of N: ");
scanf("%lf",&n);
for(i=1;i<=n;i++)
{
sum = sum + (1/i);
if(i==1)
printf("\n 1 +");
else if(i==n)
printf(" (1/%f) ",i);
else
printf(" (1/%f) + ",i);
}
printf("\n\n THE SUM OF THIS SERIES IS %.2lf",sum);
getch();
}
/*
Input: Please Give The Value of N: 5
*/
/*Result will be 2.28*/
Summary: Print sum of series
1 + 1/2 + 1/3 + 1/4 + ... + 1/N.
*/
#include<stdio.h>
#include<conio.h>
int main()
{
double n,sum=0,i;
clrscr();
printf("\n Please Give The Value of N: ");
scanf("%lf",&n);
for(i=1;i<=n;i++)
{
sum = sum + (1/i);
if(i==1)
printf("\n 1 +");
else if(i==n)
printf(" (1/%f) ",i);
else
printf(" (1/%f) + ",i);
}
printf("\n\n THE SUM OF THIS SERIES IS %.2lf",sum);
getch();
}
/*
Input: Please Give The Value of N: 5
*/
/*Result will be 2.28*/
No comments:
Post a Comment