Wednesday 19 October 2016

C Program to Swap two values or numbers using two varriable

This is a C program to swap two variable values(a,b). This is done using two variables only.

Code:
#include <stdio.h>
#include<conio.h>
void main()
{int a,b;
    printf("\t\t\t Swaping the values\n");
    printf("Enter the values of a and b");

scanf("%d%d",&a,&b);
printf("Before  swapping \n a=%d \n b=%d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\nAfter swapping \n a=%d \n b=%d",a,b);
getch();
}

Output:

Enter the values of a and b 5 8
Before  swapping
 a=5
 b=8
After swapping
 a=8
 b=5

No comments:

Post a Comment