create a c-program that shows the comparative values of the elements of arithmetic, geometric and harmonic progression in table. inputs include a1-first term, d or r - common difference or ratio, and n-number of terms or elements
//Print in table all terms arithmetic, geometric and harmonic progression#include <stdio.h>
#include <stdlib.h>
int main() {
double a1;//First term
double bn,an;
double hn;
double b1;//
double d;//common difference
double r;//ratio
printf("Please first term:");
scanf("%lf",&a1);
printf("Please enter d: ");
scanf("%lf",&d);
printf("Please enter ratio:");
scanf("%lf",&r);
int n;//size
printf("Please enter size(n): ");
scanf("%i",&n);
double qn=1;
b1=a1;
printf("|n-|");
for(int i=1;i<=n;i++)
{
printf("|%7d|",i);
}
printf("\n");
printf("|an|");
for(int i=1;i<=n;i++)
{
an=a1+(i-1)*d;
printf("|%7.3lf|",an);
}
printf("\n");
printf("|bn|");
for(int i=1;i<=n;i++)
{
bn=a1*qn;
qn*=d;
printf("|%7.3lf|",qn);
}
printf("\n");
printf("|hn|");
for(int i=1;i<=n;i++)
{
hn=1.0/(a1+(i-1)*d);
printf("|%7.3lf|",hn);
}
printf("\n");
}
//This code build and run on Lunix compiler but it running all OS
Comments
Leave a comment