C++ Programming Blog

 
 
 

Image

 #include<iostream.h>
 #include<conio.h>
 #include<iomanip.h>
 #include\"swap.h\" // Attached in source code zip


 main()
    {
       clrscr();

       int int_1=2;
       int int_2=3;

       char char_1=\'A\';
       char char_2=\'B\';

       float float_1=2.5;
       float float_2=3.0;

       cout<<\"\\n ******** Integers ********\"<<endl;

       cout<<\"Before swap :\"<<endl;
       cout<<setw(15)<<\"int_1 = \"<<int_1<<endl;
       cout<<setw(15)<<\"int_2 = \"<<int_2<<endl;

       swap(&int_1,&int_2);

       cout<<\"After swap :\"<<endl;
       cout<<setw(15)<<\"int_1 = \"<<int_1<<endl;
       cout<<setw(15)<<\"int_2 = \"<<int_2<<endl;

       cout<<\"******* Characters *******\"<<endl;

       cout<<\"Before swap :\"<<endl;
       cout<<setw(15)<<\"char_1 = \"<<char_1<<endl;
       cout<<setw(15)<<\"char_2 = \"<<char_2<<endl;

       swap(&char_1,&char_2);

       cout<<\"After swap :\"<<endl;
       cout<<setw(15)<<\"char_1 = \"<<char_1<<endl;
       cout<<setw(15)<<\"char_2 = \"<<char_2<<endl;

       cout<<\"********* Floats *********\"<<endl;

       cout<<\"Before swap :\"<<endl;
       cout<<setw(15)<<\"float_1 = \"<<float_1<<endl;
       cout<<setw(15)<<\"float_2 = \"<<float_2<<endl;

       swap(&float_1,&float_2);

       cout<<\"After swap :\"<<endl;
       cout<<setw(15)<<\"float_1 = \"<<float_1<<endl;
       cout<<setw(15)<<\"float_2 = \"<<float_2<<endl;

       getch();
       return 0;
    }

 
 
Didn't find what you were looking for? Find more on Program to swap two variables using header file swap.h