Header Ads

Geometric Progression in C

In mathematics, a geometric progression (also inaccurately known as a geometric series) is a sequence of numbers such that the quotient of any two successive members of the sequence is a constant called the common ratio of the sequence.
a geometric sequence can be written as:
aq0=a, aq1=aq, aq2, q3, ... where q ≠ 0q is the common ratio and a is a scale factor.
A sequence with a common ratio of 2 and a scale factor of 1 is
1, 2, 4, 8, 16, 32...
A sequence with a common ratio of -1 and a scale factor of 5 is
5, -5, 5, -5, 5, -5,...

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

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


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

Screenshot for GP in C

No comments