python programming.. - Write a program in which displays the sum of the first 50
ID: 3759623 • Letter: P
Question
python programming..
- Write a program in which displays the sum of the first 50 integers , modify the program so that the user can specify how many integers to sum. For example, if the user enters 5, the program returns the sum of the first 5 integers.
-Define a function that has a single parameter and returns a magic number. The magic number is calculated by multiplying the parameter value by 34 and dividing it by 4. Call the function 3 times with 3 different values and display the result each time.
Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
int positiveInteger;
int startingNumber = 1;
cout << "Please input an integer upto 100." << endl;
cin >> positiveInteger;
int result = 0
for (int i=startingNumber; i <= positiveInteger; i++)
{
result += i
cout << result;
}
cout << result;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.