Swapping Values in C language

Swapping Values in C language 

Q:-Write a program to swap two values get from the users:-

#include <stdio.h>
int main() {
int a,b,temp;
printf("Enter 1st number:");
scanf("%d",&a);
printf("Enter 2nd number:");
scanf("%d",&b);
temp=a;
a=b;
b=temp;
printf("The values after swapping become first number = %d and second number = %d\n",a,b);
return 0;
}


=> Write a program which swaps two value without using third variable in C Language.

#include<stdio.h>
int main(){
int s,f;
printf("Enter first number ");
scanf("%d",&f);
printf("Enter first number ");
scanf("%d",&s);
printf("before first number = %d and second number = %d",f,s);
f=f+s;
s=f-s;
f=f-s;
printf("\nAfter first value = %d and second value = %d",f,s);
}


Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.