Advertisement
fahimkamal63

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

Oct 6th, 2019
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.37 KB | None | 0 0
  1. //  1 + 1/2 + 1/3 ........ 1/n
  2. //  Date : 06.10.19
  3. #include<stdio.h>
  4. int main(){
  5.     int n;
  6.     printf("Enter the range of series: ");
  7.     scanf("%d", &n);
  8.     printf("The series is: 1 + ");
  9.     float sum = 1;
  10.     for(int i = 2; i<= n; i++){
  11.         printf("1/%d ", i);
  12.         sum = sum + (1.0/i);
  13.         if(i != n) printf("+ ");
  14.     }
  15.     printf(" = %f", sum);
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement