Back to Top

Thursday 2 April 2015

C++ Solutions: Chapter 2

Here is the code for Q4 in chapter 2

1) By using 3 variables-

#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int a,b,temp;
cout<<”Enter a and b”;
cin>>a>>b;
temp=a;
a=b;
b=temp;
}

2) By using 2 variables-

#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int a,b,temp;
cout<<”Enter a and b”;
cin>>a>>b;
a=a+b;
b=a-b;
a=a-b;
}

Smash +1, if you solved it before this post! Lets see how many were able to do so!!