/* Swap the values of two variables without using third variable */
#include<stdio.h>
int main()
{
int a;
int b;
printf("Type value of A : ");
scanf("%i",&a);
printf("\nType value of b : ");
scanf("%i",&b);
a = a + b;
b = a - b;
a = a - b ;
printf("A : %i",a);
printf("\nB : %i",b);
return 0;
}
Related Posts:
------------------------------------------------------------------------------
Swap values of two variables using XOR
http://cbasicprogram.blogspot.com/2012/01/swap-two-variables-using-xor.html
Swap values of two variables
http://cbasicprogram.blogspot.com/2012/01/swap-values-of-two-variables-c-program.html
#include<stdio.h>
int main()
{
int a;
int b;
printf("Type value of A : ");
scanf("%i",&a);
printf("\nType value of b : ");
scanf("%i",&b);
a = a + b;
b = a - b;
a = a - b ;
printf("A : %i",a);
printf("\nB : %i",b);
return 0;
}
Related Posts:
------------------------------------------------------------------------------
Swap values of two variables using XOR
http://cbasicprogram.blogspot.com/2012/01/swap-two-variables-using-xor.html
Swap values of two variables
http://cbasicprogram.blogspot.com/2012/01/swap-values-of-two-variables-c-program.html
many many thanx
ReplyDeletesame program using function
ReplyDeleteThanks
ReplyDeletesuperb site
ReplyDeletehow to swap values of 2 variables using function where arguments are passed by reference
ReplyDeletehi all
ReplyDeleteeven this works
a = a ^ b;
b = a ^ b;
a = a ^ b ;
and
a = a * b;
b = a / b;
a = a / b ;
Awesome!! Tysm!!
ReplyDelete#include
ReplyDelete#include
void main()
{
int x = 10, y = 15;
x = x + y - (y = x);
printf("x = %d and y = %d",x,y);
getch();
}
you can refer to this link for detail answer about the topic:
https://www.studytonight.com/c/programs/basic/swapping-two-numbers-program
https://www.studytonight.com/c/programs/basic/swapping-two-numbers-program
ReplyDeleteNice
ReplyDeleteYou can refer from here
ReplyDeleteStudyTonigt