Question

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

please go through screenshots for better understanding.Any doubts comment.Thank you.

C++ code:

#include<iostream>
using namespace std;
void calculate(double n) // implementing method calculate
{
double sum = 0; // initializing sum as 0
int i;
for(i=1;i<=n;i++) // loop series
{
sum = sum + (i/n); // calculating sum for series
}
cout<<"result = "<<sum; // printing sum
}

int main()
{
double n;
cout<<"Enter number: "; // prompting user to enter number
cin>>n; // reading input from user
calculate(n); // passing number to method calculate
return 0;
}

Add a comment
Know the answer?
Add Answer to:
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...
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
  • 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...

  • Write a program to display the sum of the series 1 + 1/2 + 1/3 +...

    Write a program to display the sum of the series 1 + 1/2 + 1/3 + L + 1/n [Use positive integer value n as provided by the user using a scanf statement] in terms of C

  • Using c++.. 1. Write a program to find the sum(), Subtraction(), Multiplication(), Division() operations using Switch...

    Using c++.. 1. Write a program to find the sum(), Subtraction(), Multiplication(), Division() operations using Switch statement and functions. 2. Write a program to find the summation of N numbers. Use two functions. One function will take the input from user and the other will perform the summation from 1 to N. 3. Write a program to find the factorial of a number. Use two functions. One function will take the input from user and the other will perform the...

  • 3. Write a complete C++ program that finds and prints the sum of values from 1...

    3. Write a complete C++ program that finds and prints the sum of values from 1 to N where N is a positive value > 10 entered by the user. If the user inputs a value less the 10 ask him to re-enter the value again and again until the value is valid. (20 Points)

  • 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...

  • Write a complete C++ program to ask the user to enter 4 integers. The program must...

    Write a complete C++ program to ask the user to enter 4 integers. The program must use a function to find the smallest integer among them and print it on the screen. Typical output screen should be as following: Write a complete C++ program to ask the user to enter 4 integers. The program must use a functionto find the smallest integer among them and print it on the screen. Typical output screen should be as following: Note: the code...

  • Write a complete Java program, including comments in both the main program and in each method,...

    Write a complete Java program, including comments in both the main program and in each method, which will do the following: 0. The main program starts by calling a method named introduction which prints out a description of what the program will do. This method is called just once.      This method is not sent any parameters, and it does not return a value. The method should print your name. Then it prints several lines of output explaining what the...

  • Write a C++ program that computes the following series: sum = 1/firstPrime + 2/secondPrime+…..+1/nthPrime Your program...

    Write a C++ program that computes the following series: sum = 1/firstPrime + 2/secondPrime+…..+1/nthPrime Your program should prompt the user to enter a number n. The program will compute and display sum based on the series defined above. firstPrime: is 2 secondPrime: the first prime number after 2 thirdPrime: the third prime number …. nth prime: the nth prime number Your program must be organized as follows: int main() { //prompt the user to enter n //read n from the...

  • important don't use arrays or listed pleaseeeee in python 3 Write a program that given a...

    important don't use arrays or listed pleaseeeee in python 3 Write a program that given a collection of ?N numbers will find the largest value, its frequency and the average of the ?N numbers. Get the value of ?N from the user. If ?≤0N≤0, display an appropriate error message and terminate the program; otherwise Read the values as entered from the user. (If ?=5N=5, then there are 5 values the user is going to enter). Find the largest, its frequency...

  • Write a complete C++ program to ask the user to enter 4 integers. The program must...

    Write a complete C++ program to ask the user to enter 4 integers. The program must use a function to find the LARGEST integer among them and print it on the screen. Typical output screen should be as following: Note: the code must contain function to find the LARGEST number. Enter four integers 1 2 4 0 Largest integer is 4

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