### Sample C Program To Swap Two Numbers Using & Without Temporary Variables.

#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

### Popular posts from this blog

Try to introduce some of your most important employment-oriented skills as well as your education and accomplishments to the interviewer. Answer to this question is very important because it positions you for the rest of the interview. That's why this statement is often called the "Positioning Statement".

One should take the opportunity to show his/her communication skills by speaking clearly and concisely in an organized manner. Since there is no right or wrong answer for this question hence it is important to appear friendly.

1) I am a person with strong interpersonal skills and have the ability to get along well with people. I enjoy challenges and looking for creative solutions to problems.

2) Besides the details given in my resume, I believe in character values, vision and action. I am quick in learning from mistakes. I am confident that the various tests that you have conducted will corroborate my competencies aptitude and right attitude for the…

### 100 C Programs Frequently Asked in Technical Interview.

The interviewer asks this question just to find out how your skills, experience and knowledge can add value to the job.Well to answer this question you need to learn what they are looking for and then tie them with your strengths. This ensures that you are a viable fit for the position.

The more detail you give the stronger your answers will be. Try to summarize all your accomplishments and relate what makes you unique.

The question can also be

"Why should we hire you over other candidates?"
OR
"Why should we hire you over the others waiting to be interviewed?"