Advertisement
AedenCak3

Geometric sequence using for loop

Nov 10th, 2021
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.46 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int i,min,max,sum=0, ratio;
  5.  
  6.     printf("Enter the minimum value: ");
  7.     scanf("%d", &min);
  8.     printf("Enter the maximum value : " );
  9.     scanf("%d", &max);
  10.     printf("Enter the common ratio :");
  11.     scanf("%d", &ratio);
  12.  
  13.  
  14.     for (i=min ; i<=max ; i*=ratio){
  15.         printf("%d\n", i);
  16.         sum=sum+i ;
  17.     }
  18.  
  19.  
  20.       printf("the sum of the geometric series is: %d\n", sum);
  21.  
  22.  
  23.  
  24.  
  25.  
  26.     return 0;
  27.  
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement