Tuesday 20 August 2013

Write A Program to Add Two Numbers Without Using Plus ( + ) Operator


# include < iostream.h >
# include < conio.h >


void main ( )
{
int Num1 , Num2,Num3;
int counter;

cout<<"Enter First Number :-"
cin>>Num1;
cout<<endl;

cout<<"Enter Second Number :-"
cin>>Num2;
cout<<endl;

for ( counter=0; counter <Num2-1; counter++ )
{
Num1++;
}

Cout<<"Addition of "<<Num3<<" and "<<Num2<<"is :- "<<Num1;

getch ( );
}

DESCRIPTION

Step1
* These are the Header Files that contain the functions like getch( ) , cin, cout described in them
   # include < iostream.h >
   # include < conio.h >

Step2
* Now we have get our two values that are to be added taken from user using cin statements 

cout<<"Enter First Number :-"
cin>>Num1;
cout<<endl;

cout<<"Enter Second Number :-"
cin>>Num2;
cout<<endl;

Here endl is used for empty line 

Step3
* Now Loop counter variable will start from 0 and it will continue to value in Num2 variable -1 

for ( counter=0; counter <Num2-1; counter++ )
{
Num1++;
}

if value of Num2 is 5 then loop will done from 0 to 4 and it will increment the value of Num1 variable Num2-1 times

Share this

0 Comment to "Write A Program to Add Two Numbers Without Using Plus ( + ) Operator"

Post a Comment