Header Ads

Arithmetic Progression in C

An arithmetic progression is a sequence of numbers such that the difference of any two successive members of the sequence is a constant.
For example, the sequence 1, 2, 3, 4, ... is is an arithmetic progression with common difference 1.
Second example: the sequence 3, 5, 7, 9, 11,... is an arithmetic progression
with common difference 2.
Third example: the sequence 20, 10, 0, -10, -20, -30, ... is an arithmetic progression
with common difference -10.

****************************Program*******************************

#include<stdio.h>
#include<conio.h>
main()
{
    int a,n,d,t;
    printf("Enter the first term of your AP : ");
    scanf("%d",&a);
    printf("Enter the difference b/w terms : ");
    scanf("%d",&d);
    printf("Enter the number of terms you want to get in your AP : ");
    scanf("%d",&n);
    printf("AP of your given data is :\n%d ",a);
    while(n>=0)
    {
        t=a+d;
        printf("%d ",t);
        a=t;
        n--;
    }
    getch();
}


****************************Output********************************

screenshot for output of AP in C program

No comments