Question

Write a program that reads a positive integer N, where N is greater than 1 and...

Write a program that reads a positive integer N, where N is greater than 1 and prints the value of the floating-point value SUM where SUM is the results of the following series.

SUM = 1/1! + 2/2! + 3/3! + 4/4! + ... N/N!
Note that your program should print the message “Sorry, bad N”” if N is <=1, and keep reading user input until the user enters a valid value for N.
Also, note that all division operations in your program must be floating-point operations.

using c programming,

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>

int main() {
    int n, i;
    double sum = 0, f = 1;
    printf("Enter a positive integer for n: ");
    scanf("%d", &n);
    while (n <= 1) {
        printf("Sorry, bad N\n");
        printf("Enter a positive integer for n: ");
        scanf("%d", &n);
    }
    for (i = 1; i <= n; ++i) {
        f *= i;
        sum += i/f;
    }
    printf("Sum = %lf\n", sum);
    return 0;
}

Add a comment
Know the answer?
Add Answer to:
Write a program that reads a positive integer N, where N is greater than 1 and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Part A Write a Java program that reads an integer n from the keyboard and loops...

    Part A Write a Java program that reads an integer n from the keyboard and loops until −13 ≤ n ≤ 13 is successfully entered. A do-while loop is advised. Part B Write a Java program that reads an integer n from the keyboard and prints the corresponding value n!. [This is n factorial]. You must verify that the input integer satisfies the constraint 0 ≤ n ≤ 13; keep looping until the constraint is satisfied.   Will give thumbs up...

  • using C++ Write a program that: a) Inputs an integer n from the keyboard where n<=100....

    using C++ Write a program that: a) Inputs an integer n from the keyboard where n<=100. If n is out of range then print out an error message and ask for another input. This process repeats until a valid value for n is obtained. b) Inputs two 1D arrays of doubles A and B (of size n) from the keyboard. c) Inputs an integer k (from 1 to 3) from the keyboard. d) If k = 1 then it calculates...

  • Q#1 Write a C++ program that reads n integer values and stores them in an array...

    Q#1 Write a C++ program that reads n integer values and stores them in an array of maximum 20 integers. Read from the user a valid value of n (n should not exceed 20). After reading the n array elements find the maximum and minimum elements.

  • Write a program that reads an integer greater or equal to 2, n, and prints a...

    Write a program that reads an integer greater or equal to 2, n, and prints a shape of a nline hollow inverted pyramid of stars. Your program should interact with the user exactly as it shows in the following two executions: Execution example 1: Please enter an integer, greater or equal to 2: 5 ********* -*----- * --*--- * ---*--* ----* Execution example 2: Please enter an integer, greater or equal to 2: 3 ***** -* * --*

  • IN C++ Pleaseeeee Write a program to find the sum of the series 1/n+2/n+3/n+4/n+...+n/n, where 1...

    IN C++ Pleaseeeee Write a program to find the sum of the series 1/n+2/n+3/n+4/n+...+n/n, where 1 <= n <= 8 using a function. The user is asked to enter an integer value n. Then the program calls the appropriate function to calculate the sum of the series and then prints the sum to the screen.

  • Problem 1: Write a program that reads a positive float number and displays the previous and...

    Problem 1: Write a program that reads a positive float number and displays the previous and next integers. Sample Run: Enter a float: 3.5 The previous and next integers are 3 and 4. Problem 2: Write a program that reads two integers and displays their sum, difference, product, and the result of their division. Sample Run: Enter two integers: 8 5 Sum: 8, Difference: 3, Product: 40, Division: 1.6 Problem 3: Write a program that reads a three-digit integer from...

  • JAVA. Write a program that reads in a series of positive integers and prints out the...

    JAVA. Write a program that reads in a series of positive integers and prints out the maximum value entered. The user will indicate they are finished entering numbers by entering zero or a negative integer.

  • Write a program that receives a positive integer n from the user and then calculates the...

    Write a program that receives a positive integer n from the user and then calculates the sum below by using a loop. Your program needs to ask the user to re-enter a different number if the user enters a non-positive one. Display the result. 1 SUM 1 2 3 ... n x x n = = = + + + +

  • A java program Write a program that prompts for and reads in a positive    integer...

    A java program Write a program that prompts for and reads in a positive    integer into a variable n. Your program should then sum    the first n ODD integers and display the sum. For    example, if 3 is entered for n, your program should display    the the sum 1 + 3 + 5. If 5 is entered, your program should    display the sum 1 + 3 + 5 + 7 + 9. What is the...

  • Task 1 : Write a Java program that prompts for and reads 10 integers from the...

    Task 1 : Write a Java program that prompts for and reads 10 integers from the user into an integer array of size 10, it then: - calculates the sum and average of positive numbers of the array and displays them. [Note: consider 0 as positive] Note: The program must display the message: "There are no positive values" if the array does not contain any positive value.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT