Question : Write a C Program to swap two numbers with and without using third variable.
/*
Write a C Program to swap two numbers with and without using third variable.
*/
#include <stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter the Values for a & b to Swap: ");
scanf("%d %d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("After Swapping the Values of a & b are :%d %d",a,b);
getch();
}
OUTPUT :
Enter the Values for a & b to Swap: 10 20
After Swapping the Values of a & b are :20 10
Thank you very much for reading carefully, if you have any other questions, you can share it with us through comments, if this information was important to you, please let us know through comments.
Please do comment and share.
Thank You.
No comments:
Post a Comment