How to swap two variables, without using third variable ?

Answer Posted / rehan

#include<stdio.h>
main()
{
int a,b;
printf("Enter any two numbers\n");
scanf("%d%d",&a,&b);
printf("The values before swapping are\n%d %d\n",a,b);
swap(&a,&b);
printf("The values after swapping are\n%d %d\n",a,b);
getch();
}

swap(*x,*y)
{
int t;
t=*x;
*x=*y;
*y=t;
}

Is This Answer Correct ?    5 Yes 24 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

To Write a C program to remove the repeated characters in the entered expression or in entered characters(i.e) removing duplicates. String contains only lowercase characters ['a'-'z']

758


Write a Program in 'C' To Insert a Unique Number Only. (Hint: Just Like a Primary Key Numbers In Database.) Please Some One Suggest Me a Better Solution for This question ??

2180


how to programme using switch statements and fuctions, a programme that will output two even numbers, two odd numbers and two prime numbers of the users chioce.

2382


write a simple calculator c program to perform addition, subtraction, mul and div.

3419


What is the difference between proc means and proc tabulate ? explain with a simple example when you have to use means or tabulate?

4098


could you please send the program code for multiplying sparse matrix in c????

3321


Set up procedure for generating a wire frame display of a polyhedron with the hidden edges of the object drawn with dashed lines

3291


What is data _null_? ,Explain with code when u need to use it in data step programming ?

3049


How can you relate the function with the structure? Explain with an appropriate example.

3152


A program that will create a movie seat reservation. The program will display the summary seats and its status. The user will be ask what seat no. to be reserved, then it will go back again to the summary to display the updated seat status. If the seat no. is already reserved then it will prompt an error message. And also if the input seat no is out of range then it will also prompt an error message. The program is continuously running. Termination of the program will depends on how the programmer will apply. Sample output: Movie Seats Reservation Summary of Seats: Seat 1: Available Seat 2: Available Seat 3: Available Seat 4: Available Seat 5: Available Enter seat no. (Press 0 to terminate Or the assigned seat capacity) : 1 Movie Seats Reservation Summary of Seats: Seat 1: Reserve Seat 2: Available Seat 3: Available Seat 4: Available Seat 5: Available Enter seat no. (Press 0 to terminate Or the assigned seat capacity) : 6 The Seat no. is out of range! Movie Seats Reservation Summary of Seats: Seat 1: Reserve Seat 2: Available Seat 3: Available Seat 4: Available Seat 5: Available Enter seat no. (Press 0 to terminate Or the assigned seat capacity) : 1 The Seat no. is already reserved! Movie Seats Reservation Summary of Seats: Seat 1: Reserve Seat 2: Available Seat 3: Available Seat 4: Available Seat 5: Available Enter seat no. (Press 0 to terminate Or the assigned seat capacity) : 0 GoodBye... Thank You!!!

2100


how to test pierrot divisor

2499


why do you use macros? Explain a situation where you had to incorporate macros in your proc report? use a simple instream data example with code ?

2540


Sir... please give some important coding questions asked by product companies..

2054


What is full form of PEPSI

2154


Write a routine to implement the polymarker function

4615