sum of the integers

Write a C++ program to find the sum of all the numbers. The numbers are entered and the program terminates when you enter 0. Use do while loop in C++.

#include<iostream>
using namespace std;
int main(){
	int n,sum=0;
	cout<<"Find the sum of the integers"<<endl;
	cout<<"Enter the numbers : "<<endl;
	cin>>n;
	do{
		sum = sum+n;
		cin>>n;
	}while(n);
	cout<<"The sum of the integers is "<<sum;
	return 0;
}
output of the above program. enter 0 to quit.

Leave a Reply