Generally The program runs only one set of data means program takes value of a and value of b then gives addition of c as output. If we would like to add more values we need to run/execute the program again. To overcome this problem the program below, adds two numbers several times until you give 0 (zero) value for a.
Here is the program :
#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int a,b,c;
for (int i=1; a!=0; i++)
{
cout <<"enter any number";
cin >> a;
cout <<"enter any number";
cin >> b;
c=a+b;
cout << "Value of C is="<<c <<endl;
cout << "------------------------"<<endl;
getch();
}
}
Here in the above program for loop is used to make the condition to take several data until 0 value of "a" variable is entered. The above program can be used to add two numbers many times.
No comments:
Post a Comment