Answer to Question #331863 in C++ for Shy

Question #331863

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

1
Expert's answer
2022-04-22T13:30:50-0400


//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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS