Write a C program that repeatedly receives a positive integer number from the user and display the results of the following equation: 1 1 1 1 ++ 2! 3! 4! (n+1)! Notel: If n <= 0 or n >= 8, display an error message and repeat the process by geting another input from the user. The program should terminate if the user does not want to try again. Sample execution: Please enter a positive integer value (between 1 and 7, inclusive): 6 1/2 + 1/6 + 1/24 + 1/120+ 1/720+ 1/5040 = 0.718 Do you want to try again? (1/yes, 0/no) 1 Please enter a positive integer value (between 1 and 7, inclusive): 1 1/2 = 0.500 Do you want to try again? (1/yes, 0/no) 1 Please enter a positive integer value (between 1 and 7, inclusive): 0 Invalid input. inclusive): 1 Please enter a positive integer value (between 1 and 7, 1/2 = 0.500 Do you want to try again? (1/yes, 0/no) 1 Please enter a positive integer value (between 1 and 7, inclusive): 7 1/2 + 1/6 + 1/24 + 1/120 + 1/720 + 1/5040 + 1/40320 = 0.718 Do you want to try again? (1/yes, 0/no) 0 Coodbuol +=+

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

/***************************************************************************** *

Online C Compiler.
Code, Compile, Run and Debug C program online.

Write your code in this editor and press "Run" button to compile and execute it.

****************************************************************************** */

#include <stdio.h>

int main()

{
int e=1;

while(e)

{ int n;
puts("please enter a positive integer value (betweenn 1 and 7, inclusive)"); scanf("%d",&n);
if (n>7)
puts("Invalid input");
else if (n<=0)
puts("Invalid input");
else
{

long fact=1; float sum=0; int i=1;

while (i<=n) {fact=fact*(i+1);

sum= sum +(1.0/fact); if (i<n) printf("1/%ld+",fact); else printf("1/%ld=",fact); i++;

}

printf("%.3f\n",sum); }

puts("Do you want to try again? 1/yes, 0/no"); int answer;
scanf("%d",&answer);
if (answer==0)

e=0;

} puts("Goodbye!");

return 0; }

 

Write a C program that repeatedly receives a positive integer number from the user and
display the results of the following equation:
1 1 1
+
1
+
21 +31
3! 4!
(n + 1)!
Notel: If n <= 0 or n>= 8, display an error message and repeat the process by geting
another input from the user. The program should terminate if the user does not want to
try again.
Sample execution:
Please enter a positive integer value (between 1 and 7, inclusive): 6
1/2 + 1/6 + 1/24 + 1/120 + 1/720+ 1/5040 = 0.718
Do you want to try again? (1/yes, 0/no) 1
Please enter a positive integer value (between 1 and 7, inclusive): 1
1/2 = 0.500
Do you want to try again? (1/yes, 0/no) 1
Please enter a positive integer value (between 1 and 7,
Invalid input.
inclusive): 0
Please enter a positive integer value (between 1 and 7,
1/2 = 0.500
inclusive): 1
Do you want to try again? (1/yes, 0/no) 1
Please enter a positive integer value (between 1 and 7, inclusive): 7
1/2 + 1/6 + 1/24 + 1/120 + 1/720 + 1/5040 + 1/40320 = 0.718
Do you want to try again? (1/yes, 0/no) 0
Goodbye!
Transcribed Image Text:Write a C program that repeatedly receives a positive integer number from the user and display the results of the following equation: 1 1 1 + 1 + 21 +31 3! 4! (n + 1)! Notel: If n <= 0 or n>= 8, display an error message and repeat the process by geting another input from the user. The program should terminate if the user does not want to try again. Sample execution: Please enter a positive integer value (between 1 and 7, inclusive): 6 1/2 + 1/6 + 1/24 + 1/120 + 1/720+ 1/5040 = 0.718 Do you want to try again? (1/yes, 0/no) 1 Please enter a positive integer value (between 1 and 7, inclusive): 1 1/2 = 0.500 Do you want to try again? (1/yes, 0/no) 1 Please enter a positive integer value (between 1 and 7, Invalid input. inclusive): 0 Please enter a positive integer value (between 1 and 7, 1/2 = 0.500 inclusive): 1 Do you want to try again? (1/yes, 0/no) 1 Please enter a positive integer value (between 1 and 7, inclusive): 7 1/2 + 1/6 + 1/24 + 1/120 + 1/720 + 1/5040 + 1/40320 = 0.718 Do you want to try again? (1/yes, 0/no) 0 Goodbye!
Expert Solution
steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY