Question

Write a C++ program using a function called sum that calculates the following summation: p=2+5 F = i2 + 5 i=1 Where n is prov

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

#include<iostream>

using namespace std;

int sum(int n)

{

int sum1=0;

for(int i=1;i<=n;i++)

sum1+= i*i+5;

return sum1;

}

int main()

{

int n;

cout<<"\nEnter the value of n:";

cin>>n;

cout<<"\nThe sum of the numbers is :"<<sum(n);

}

CppDroid project_mayo2a.cpp Navigator Editor 1 #include<iostream> 2 using namespace std; 3 int sum(int n) 4 { 5 int sum1=0; 6

CppDroid terminal Stopped Enter the value of n:5 The sum of the numbers is : 80

If you have any questions comment down and please upvote thanks

Add a comment
Know the answer?
Add Answer to:
Write a C++ program using a function called sum that calculates the following summation: p=2+5 F...
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
  • 1. Write a function to add two integers and return the summation. (Each box is 5...

    1. Write a function to add two integers and return the summation. (Each box is 5 points.) a. Prototype a function: b. In main function; i. Take two integers from user: ii. Define 2 variables and call the function into main function to take the sum: Print the summation: C. Define the function to return the sum:

  • in c++ language 1.Re-write the following for loop statement by using a while loop statement: int...

    in c++ language 1.Re-write the following for loop statement by using a while loop statement: int sum = 0; for(int i=0;i<=1000;i++){                 sum+=i; } 1 (b). Following is the main () function of a program. The program asks a user to enter 150 integers and print the largest integer user entered. int main() {    int score, highest;             //missing portion of the program             return 0;    } 1(c). Find the missing portion of the following code, so the...

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

  • Student ID: 123 Write a C+ program with the following specifications: a. Define a C++ function (name it function_Student...

    Student ID: 123 Write a C+ program with the following specifications: a. Define a C++ function (name it function_StudentlD where StudentID is your actual student ID number) that has one integer input (N) and one double input (x) and returns a double output S, where N S = n 0 and X2 is given by 0 xeVn n 0,1 Хл —{2. nx 2 n 2 2 m2 x2 3 (Note: in the actual quiz, do not expect a always, practice...

  • Using C++ language please not matlab a. Write a function, called SumOfDigits that is able to...

    Using C++ language please not matlab a. Write a function, called SumOfDigits that is able to calculate the summation of a five-digit number. This function receives one integer parameter 'a', then returns the sum of 5 digits of the number. [2.5 marks] b. Write a function, called Armstrong that prints all Armstrong numbers in the range of 0 and 500. An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is...

  • Done in C++ using visual studio 1. Write a program with one additional function called int[]...

    Done in C++ using visual studio 1. Write a program with one additional function called int[] reverseArray(int array). This function will receive an array from main and then reverse and should return the reversed array to the main to print out. Use a single array and a single loop, you’re are neither allowed to print out just in reverse order nor allowed to use another array variable to store the original array in reverse order. 2. Write a program which...

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

  • Using C++ Reference Parameters Assignment Write a program that asks the user for 3 numbers, sends...

    Using C++ Reference Parameters Assignment Write a program that asks the user for 3 numbers, sends the numbers to a function that calculates the sum and product and returns the sum and product to the main function. In the main function, use a cout statement to display the sum and product. * You are returning the multiple values sum and product.

  • I want to create a program that first calculate the summation from 1 to R. This code will computes the summation from 1...

    I want to create a program that first calculate the summation from 1 to R. This code will computes the summation from 1 to R with single thread. #include <pthread.h> #include <unistd.h> #include <stdlib.h> #include <assert.h> #include <stdio.h> #define NuMBer_THREADS 2 #define R 1e4 long long sum = 0; // matrix multiplication is  c = a * b; void calculatesum() { int i=1; for(i=1;i<=N;i++) { sum+=i; asleep(100); } } // Thread function // Each thread calculates the summation over (R...

  • 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 = = = + + + +

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