As the topic state it is very clear for one to understand that how to add and sub. Using if else. Now most of u will be thinking that this can be done buy simple programming then why to use if else. Ya your thinking is absolutely correct we don’t have to use if else while adding but imagine u are subtracting using simple programming and a user entered values as follows:-
You’re coding for Subtraction using simple programming:-
C= (a-B);
Suppose user entered a=10 and b= 8 then answer will come 2. But if user entered a=8 b=10 then answer will come -2. So to come out from this -2 mistake[Actually it is not a mistake but we have to get positive value] we use if else so the coding goes as follows:-
Code:
#include
#include
void main()
{
clrscr();
int a,b,c;
cout<<”Enter the value of a and b\n”;
cin>>a>>b;
if(a>b)
c=(a-b);
else
c=(b-a);
cout<<”The Subtract of A and B is\t”<< c;
getch();
}
So that’s the end of if else hope u understand it plz guys if u have any confusion just ask, I am here to solve your problem .
Remind u again download the attached Program files.
No comments:
Post a Comment