Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- {
- int a,n,d,p,sum;
- int indefinite=0;
- while(indefinite==0){
- printf("\nPlease enter the first digit of the series (Type -0 to close the program): ");
- scanf("%d", &a);
- if(a==-0){
- break;
- }
- printf("Please enter the distance of the digit: ");
- scanf("%d", &d);
- printf("Please enter the total number of digits in the series: ");
- scanf("%d", &n);
- sum=(n/2)*(2*a+(n-1)*d);
- p=((2*sum)/n)-a;
- if(n>=6){
- printf("\nThe series is %d + %d + %d.....%d=%d\n", a,a+d,a+2*d,p,sum);
- }
- else if(n==5){
- printf("\nThe series is %d + %d + %d + %d + %d=%d\n", a, a+d, a+2*d, a+3*d, p,sum);
- }
- else if(n==4){
- printf("\nThe series is %d + %d + %d +%d=%d\n", a,a+d,a+2*d,p,sum);
- }
- else if(n==3){
- printf("\nThe series is %d + %d + %d=%d\n", a,a+d,a+2*d,sum);
- }
- else if(n==2){
- printf("\nThe series is %d + %d=%d\n", a,p,sum);
- }
- else{
- printf("\nThe only digit of the series is %d and the sumation is %d\n", a,sum);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment