PGhosh

C Series Problem

Mar 15th, 2014
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.11 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.     int a,n,d,p,sum;
  6.     int indefinite=0;
  7.     while(indefinite==0){
  8.     printf("\nPlease enter the first digit of the series (Type -0 to close the program): ");
  9.     scanf("%d", &a);
  10.     if(a==-0){
  11.         break;
  12.     }
  13.     printf("Please enter the distance of the digit: ");
  14.     scanf("%d", &d);
  15.     printf("Please enter the total number of digits in the series: ");
  16.     scanf("%d", &n);
  17.     sum=(n/2)*(2*a+(n-1)*d);
  18.     p=((2*sum)/n)-a;
  19.     if(n>=6){
  20.         printf("\nThe series is %d + %d + %d.....%d=%d\n", a,a+d,a+2*d,p,sum);
  21.     }
  22.     else if(n==5){
  23.         printf("\nThe series is %d + %d + %d + %d + %d=%d\n", a, a+d, a+2*d, a+3*d, p,sum);
  24.     }
  25.     else if(n==4){
  26.         printf("\nThe series is %d + %d + %d +%d=%d\n", a,a+d,a+2*d,p,sum);
  27.     }
  28.     else if(n==3){
  29.         printf("\nThe series is %d + %d + %d=%d\n", a,a+d,a+2*d,sum);
  30.     }
  31.     else if(n==2){
  32.         printf("\nThe series is %d + %d=%d\n", a,p,sum);
  33.     }
  34.     else{
  35.         printf("\nThe only digit of the series is %d and the sumation is %d\n", a,sum);
  36.     }
  37.     }
  38.  
  39.     return 0;
  40.  
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment