Swapping Two Nos in C

A simple C Program swapping two numbers. Enjoy!!! 😉 😀
Here we will be swapping two numbers using a third variable.

Level- Very Beginner


#include<stdio.h>
#include<conio.h>


int main()
{
     int a, b, c;
     a=2;
     b=3;
     
     printf("\n ~~~Swapping two Numbers in C~~~ \n");
     
     printf("\n Before Swapping \n");
      
     printf("\n a = %d", a);
     printf("\n b = %d", b);
     printf("\n");
     
     //Swapping using a third variable c.
     c=a;
     a=b;
     b=c;
    
     printf("\n After Swapping \n");
      
     printf("\n a = %d", a);
     printf("\n b = %d", b);
     
    
     getch(); 
     return 0;   
}


Snapshot

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s