C programming

Showing posts with label swap function. Show all posts
Showing posts with label swap function. Show all posts

Tuesday, April 5, 2016

C++ program to implement swapping of two numbers

#include<iostream.h>
class a
{
public:
int a,b,c;
void swap();
};
void a::swap()
{

 c=a;a=b;b=c;
cout<<"\n after swapping\n";
cout<<a<<" "<<b;
}
void main()
{
 a obj;
 cout<<"enter two nos.\n";
 cin>>obj.a>>obj.b;
 cout<<"before swapping\n";
 cout<<obj.a<<" "<<obj.b;
 obj.swap();
 }
output
enter two nos 5 8
before swapping
5 8
after swapping 5 8
Posted by Dinesh Agrawal at 8:26 AM No comments:
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Labels: C++, iostream.h, swap function, swapping, swapping with help of variable
Older Posts Home
Subscribe to: Posts (Atom)

About Me

My photo
Dinesh Agrawal
View my complete profile

Blog Archive

  • ▼  2016 (61)
    • ▼  June (9)
      • C program to understand the concept of initializat...
      • C program to make two matrix dynamically and show ...
      • C program to calculate GCD (greatest common diviso...
      • C program to save and retrieve records from extern...
      • c program to find factorial of a number without us...
      • C program to select elements from three given arra...
      • c++ program to show operation on time, add seconds...
      • C program to check given number in strong number o...
      • c program to count number of 1 in binary represent...
    • ►  May (14)
    • ►  April (15)
    • ►  March (23)
Simple theme. Theme images by fpm. Powered by Blogger.