Find Sum Of Arithmetic Progression (A.P) | user given A.P | C-Program

Sum of Arithmetic progression user given number:

Tips:

1.Take variables.
2.Use for loop. 

Code:

#include<stdio.h>

void main()

{
    int a,d,n,i,j,k,l=0,m;

    printf("Enter lst no. of A.P series: \n");

    scanf("%d",&a);

    printf("Enter the common difference: \n");

    scanf("%d",&d);

    printf("Enter the Term value:\n");

    scanf("%d",&n);

    for(m=1;m<=n;m++)

    {
        k=(m-1)*d+a;

        if(m!=n)

            printf("%d+",k);

        else

            printf("%d=",k);

        l=l+(m-1)*d+a;
    }

    printf("%d",l);

    getch();
} 

Output:

 

 

Comments

Popular posts from this blog

TOP 10 PROGRAMMING LANGAUAGES COMMING 2021 | ARTICLE

Write a C-program to swap two number:

Print Fibonacci Series using Recursion | C program :