How to swap of given number in c++.
Logic to swap two number with cpp code.
#include<iostream.h>
#include<conio.h>
#include<math.h>
class swap
{
int a,b,temp; //declaration//
public:
void get();
void cal();
};
void swap::get()
{
cout<<"\n\n enter the first number=";
cin>>a;
cout<<"\n enter the second number=";
cin>>b;
}
void swap::cal()
{
temp=a;
a=b;
b=temp;
cout<<"after swapping \n\n a="<<a<<"\n\nb="<<b;
}
void main()
{
swap ob;
clrscr();
//ob.get();
ob.cal();
getch();
}
c++ | swap of given number | program | source code
Logic to swap two number with cpp code.
#include<iostream.h>
#include<conio.h>
#include<math.h>
class swap
{
int a,b,temp; //declaration//
public:
void get();
void cal();
};
void swap::get()
{
cout<<"\n\n enter the first number=";
cin>>a;
cout<<"\n enter the second number=";
cin>>b;
}
void swap::cal()
{
temp=a;
a=b;
b=temp;
cout<<"after swapping \n\n a="<<a<<"\n\nb="<<b;
}
void main()
{
swap ob;
clrscr();
//ob.get();
ob.cal();
getch();
}
c++ | swap of given number | program | source code
0 comments: