Sum up Series
How to sum the following series:1+1/2+1/3+1/4+.......+1/n[c] #include
#include
#include
int main() {
int n; //for storing the value input by user
int i;
clrscr();
float sum=0;//It should be in float because fractional values by series
printf(“Enter the last term that you want to:?”);
scanf(“%d”,&n);
for(i=1;i<=n;i++){ sum=sum+1/(float)i;//put float for type casting } printf("The total sum of the series is %.2f",sum); getch(); } [/c]
Output of the Program: Enter the last term that you want to:?10 The total sum of the series is 2.93