Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Program to interchange two numbers

Posted By: Marea Ricci     Category: C Programming     Views: 2204

Program to interchange two numbers

Code for Program to interchange two numbers in C Programming

#include<stdio.h>
#include<conio.h>
    int x,y;
    void exchange();
    void main()
    {
        clrscr();
        printf("\n Enter The Value Of X : ");
        scanf("%d",&x);
        printf("\n Enter The Value Of Y : ");
        scanf("%d",&y);
        exchange();
        printf("\n After The exchange : ");
        printf("\n Value Of X = %d \n Value Of Y = %d",x,y);
        getch();
    }
    void exchange()
    {
        x=x+y;       /* let x = 22 & y = 12  */
y=x-y; /* x=22+12=34 so, y=34-12=22 & x=34-22=12 */
x=x-y; } /*
******
OUTPUT
******


Enter The Value Of X : 45

Enter The Value Of Y : 22

After The exchange :
Value Of X = 22
Value Of Y = 45

*/
  
Share: 


Didn't find what you were looking for? Find more on Program to interchange two numbers Or get search suggestion and latest updates.

Marea Ricci
Marea Ricci author of Program to interchange two numbers is from Venice, Italy.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!