Write a C program which takes number of integers to sum and gives following output:
Enter the number of integers you want to sum: 5
1 = 1
1+2 = 3
1+2+3 = 6
1+2+3+4 = 10
1+2+3+4+5 = 15

remember v can use only iostream and the loops v can use are for loops,while and do while loops...
for condition if else can also b used...thank u

First off this is the C++ forum and not the C one but I will show you a way of doing it in C++ since I don't know what headers C++ has and C doesn't.

#include <iostream>
using namespace std;

int main()
{
	int input, output = 0;
	cout << "Enter an integer: ";
	cin >> input;
	
	for( int i = input; i > 0; i-- )
		output += i;
		
	cout << output;
	
	system("PAUSE");
	return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.