Asked by Jnr John
Write a program that adds the sum of the given number.
Sample Output:
Enter the range of number to be added: 5
The sum of 1 to 5 is 15
Sample Output:
Enter the range of number to be added: 5
The sum of 1 to 5 is 15
Answers
Answered by
Steve
#include <iostream>
using namespace std;
int main()
{
int n,t,i;
cout << "Enter the range of numbers to be added: ";
cin >> n;
for (t=0,i=1; i<=n ; i++) {t+=i;}
cout << "The sum of 1 to " << n << " is " << t <<endl;
return 0;
}
using namespace std;
int main()
{
int n,t,i;
cout << "Enter the range of numbers to be added: ";
cin >> n;
for (t=0,i=1; i<=n ; i++) {t+=i;}
cout << "The sum of 1 to " << n << " is " << t <<endl;
return 0;
}
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.