Swapping of two numbers without using third variable....
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter the two numbers: ");
scanf("%d %d",&a,&b); // let user input a=10 b=20 //
a=a+b; // a=10+20 i.e. now a=30//
b=a-b; // b=30-20 i.e. now b=10//
a=a-b; // a=30-10 i.e. now a=20//
printf("\n After swapping values are : \n a=%d \nb=%d",a,b);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter the two numbers: ");
scanf("%d %d",&a,&b); // let user input a=10 b=20 //
a=a+b; // a=10+20 i.e. now a=30//
b=a-b; // b=30-20 i.e. now b=10//
a=a-b; // a=30-10 i.e. now a=20//
printf("\n After swapping values are : \n a=%d \nb=%d",a,b);
getch();
}
No comments:
Post a Comment