Answer to Question #341658 in C for Leo

Question #341658

Write a program to calculate the sum of the following series:

  1 + 1/2 + 1/3 + 1/4 + 1/5 + 1/6 + 1/7 + ...  + 1/20






1
Expert's answer
2022-05-16T16:07:57-0400


#include <stdio.h>


int main(void) {
 double sum=0.0;//Summ
  for(int i=1;i<=20;i++)
    {
      sum+=(1.0)/(i*1.0);
      printf("1/%i",i);
      if(i!=20)
        printf("+");
    }
  printf("=%lf\n",sum);
  return 0;
}

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