Wap to print the sum of the following series. 1+1/2+1/3+1/4..........1/10.
meet1408:
you want answer in C language ?
Answers
Answered by
1
Cls
For I =1 to 10
A=1/I
S=S+A
Next I
Print "The sum is"; S
End
For I =1 to 10
A=1/I
S=S+A
Next I
Print "The sum is"; S
End
Answered by
2
This C Program calculates the Sum of Series 1 + 1/2 + 1/3 + 1/4 + … + 1/N. This program is used to find the sum of the given series.
Here is source code of the C Program to Find the Sum of Series 1 + 1/2 + 1/3 + 1/4 + … + 1/N. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/* * C Program to find the Sum of Series 1 + 1/2 + 1/3 + 1/4 + ... + 1/N */#include <stdio.h> void main(){ double number, sum = 0, i; printf("\n enter the number "); scanf("%lf", &number); for (i = 1; i <= number; i++) { sum = sum + (1 / i); if (i == 1) printf("\n 1 +"); else if (i == number) printf(" (1 / %lf)", i); else printf(" (1 / %lf) + ", i); } printf("\n The sum of the given series is %.2lf", sum);}
Output: $ cc pgm.c $ a.out enter the number 4 1 + (1/2.000000) + (1/3.000000) + (1/4.000000) The sum of the given series is 2.08
Here is source code of the C Program to Find the Sum of Series 1 + 1/2 + 1/3 + 1/4 + … + 1/N. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/* * C Program to find the Sum of Series 1 + 1/2 + 1/3 + 1/4 + ... + 1/N */#include <stdio.h> void main(){ double number, sum = 0, i; printf("\n enter the number "); scanf("%lf", &number); for (i = 1; i <= number; i++) { sum = sum + (1 / i); if (i == 1) printf("\n 1 +"); else if (i == number) printf(" (1 / %lf)", i); else printf(" (1 / %lf) + ", i); } printf("\n The sum of the given series is %.2lf", sum);}
Output: $ cc pgm.c $ a.out enter the number 4 1 + (1/2.000000) + (1/3.000000) + (1/4.000000) The sum of the given series is 2.08
Similar questions
English,
7 months ago
English,
7 months ago
Physics,
7 months ago
English,
1 year ago
Social Sciences,
1 year ago
Chemistry,
1 year ago
Social Sciences,
1 year ago