#include <stdio.h>
#include <conio.h>
main()
{
int x, y, temp;
printf("Enter the value of x and y ");
scanf("%d %d", & x, & y);
printf("Before Swapping\nx = %d\ny = %d\n",x,y);
temp = x;
x = y;
y = temp;
printf("After Swapping\nx = %d\ny = %d\n",x,y);
getch();
return 0;
}
OUTPUT:
Enter the value of x and y 2
4
Before Swapping
x = 2
y = 4
After Swapping
x = 4
y = 2
C Program To Swap Two Numbers Without Using Temp Variable.
#include <stdio.h>main()
{
int a, b;
printf("Enter two numbers to swap ");
scanf("%d %d", & a, & b);
a = a + b;
b = a - b;
a = a - b;
printf("a = %d\nb = %d\n",a,b);
return 0;
}
OUTPUT:
Enter two numbers to swap 2
4
a = 4
b = 2
C Program To Swap Two Numbers Using Pointers.
# include <stdio.h>int main()
{
int x, y, *a, *b, temp;
printf("Enter the value of x and y\n");
scanf("%d%d", &x, &y);
printf("Before Swapping\nx = %d\ny = %d\n", x, y);
a = &x;
b = &y;
temp = *b;
*b = *a;
*a = temp;
printf("After Swapping\nx = %d\ny = %d\n", x, y);
return 0;
}
C Program To Swap Two Numbers Using Call By Reference
# include <stdio.h>
void swap(int*, int*);
int main()
{
int x, y;
printf("Enter the value of x and y\n");
scanf("%d%d",&x,&y);
printf("Before Swapping\nx = %d\ny = %d\n", x, y);
swap(&x, &y);
printf("After Swapping\nx = %d\ny = %d\n", x, y);
return 0;
}
void swap(int *a, int *b)
{
int temp;
temp = *b;
*b = *a;
*a = temp;
}
C Program To Swap Two Numbers Using Bitwise Operator XOR.
# include <stdio.h>int main()
{
int x, y;
scanf("%d%d", &x, &y);
printf("x = %d\ny = %d\n", x, y);
x = x ^ y;
y = x ^ y;
x = x ^ y;
printf("x = %d\ny = %d\n", x, y);
return 0;
}
ALSO CHECKOUT:
-- C Program To Print First Ten(10) Natural Numbers.
-- C Program To Print Fibonacci Series Upto 100.
-- C Program To Check Whether A Number Is Prime Or Not.
-- C Program To Compute The Reverse Of A Number.
-- C Program To Print A Semicolon Without Using A Semicolon.
-- C Program To Display Function Without Using The Main Function.
-- C Program To Print Any Print Statement Without Using Semicolon.
-- C Program To Display Its Own Source Code As Its Output.
-- C Program To Swap Two Strings Using strcpy() Function.
-- C Program to accept a string and print the reverse of the given string.
-- C Program To Get IP Address.
-- C Program To Accept An Integer & Reverse It.
-- C Program To Convert Given Number Of Days To A Measure Of Time Given In Years, Weeks & Days.
-- C Program To Illustrate The Concept Of Unions.
-- C Program To Find The Size Of A Union.
... Back To C++ Programs Index
... Back To C++ FAQ's Index
... Back To C Programs Index
... Back To C FAQ's Index
... Back To HR Interview Index
Comments
Post a Comment
Please share your opinions and suggestions or your experience in the comments section. This way we can all help each other...
Experienced guys can share their resumes at admin@interview-made-easy.com