C program for calculating Geometric Progression (GP)
In mathematics, a geometric progression, also known as a geometric sequence, is a sequence of numbers where each term after the first is found by multiplying the previous one by a fixed, non-zero number called the common ratio. For example, the sequence 2, 6, 18, 54, ... is a geometric progression with common ratio 3. Similarly 10, 5, 2.5, 1.25, ... is a geometric sequence with common ratio 1/2.
Examples of a geometric sequence are powers rk of a fixed number r, such as 2k and 3k. The general form of a geometric sequence is
where r ≠ 0 is the common ratio and a is a scale factor, equal to the sequence's start value.
************************************************************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**************************************************************
Output for GP in C |
No comments