program to swap two numbers

Solutions on MaxInterview for program to swap two numbers by the best coders in the world

showing results for - "program to swap two numbers"
Soukaina
15 Jan 2020
1// Method 1: With temporary variable
2temp = A
3A = B
4B = temp
5// without temporary variable
6// Method 2: Addition and subtraction
7A = A + B
8B = A - B
9A = A - B
10// Method 3: Muitply and Divide
11A = A * B
12B = A / B
13A = A / B
Andrea
21 Oct 2019
1
2#include<stdio.h>  
3 int main()    
4{    
5int a=10, b=20;      
6printf("Before swap a=%d b=%d",a,b);      
7a=a+b;//a=30 (10+20)    
8b=a-b;//b=10 (30-20)    
9a=a-b;//a=20 (30-10)    
10printf("\nAfter swap a=%d b=%d",a,b);    
11return 0;  
12}   
13
Benjamin
16 Jul 2019
1#include <stdio.h>
2#include <stdlib.h>
3
4int main()
5{
6  	//initialize variables
7	int num1 = 10;
8	int num2 = 9;
9  	int tmp;
10  	
11  	//create the variables needed to store the address of the variables
12  	//that we want to swap values
13  	int *p_num1 = &num1;
14  	int *p_num2 = &num2;
15  
16  	//print what the values are before the swap
17  	printf("num1: %i\n", num1);
18    printf("num2: %i\n", num2);
19  
20  	//store one of the variables in tmp so we can access it later
21  	//gives the value we stored in another variable the new value
22  	//give the other variable the value of tmp
23  	tmp = num1;
24  	*p_num1 = num2;
25  	*p_num2 = tmp;
26
27  	//print the values after swap has occured
28   	printf("num1: %i\n", num1);
29    printf("num2: %i\n", num2);
30  	
31	return 0;
32}
33
Garry
24 Aug 2018
1#include<stdio.h>
2
3int main()
4{
5    int x = 20, y = 30, temp;
6    
7    temp = x;
8    x = y;
9    y = temp;
10    
11    printf("X = %d and Y = %d", x, y);
12    
13    return 0;
14}
queries leading to this page
swap two numbers using function in cc program to interchange two numbersswap values in cswap function in chow to swap two numbers in c using functionto swap the values of two integer numbers a and b entered by the user 2c and display the new numbers to the user do this with using a third variableswapping numbers in chow to swap 2 numbers without 3rd variableswap 2 numbers write a program to swap two numbers using a temporary variable and display its outputwrite a code for swapping of two numbers without using the third variable 3f write a function to swap two variables without using the third variable codec swapwrite a c program to check a swapswap 2 numbers in cswap two numbers without taking a third variableswap 2 numberswap 2 numbersfunction to swap two numbersswap two user given integerswap 2 numbers without using 3rd variablesbest way to swap two numbersswap in cswap the values of 2 given variables 2c without using a third one swap two numbers using 26 and orhow to swap 2 variables without use of a 3rdswap value without third variable in cc swap to variablesswap two numbers without third variableswap two numbers using third variableuse of swap in c 1 write a program in c 2b 2b to swap two numbers sample output 3a swap two numbers 3awrite a program to swap two numbers without using a third variable swapping variable values in cswap two numbers without using third variable theoryswapping between two numbersswap values to 2 variables without using 3rd swping two numbersswap values of two variables without using third variable in cswap two variablesswap 2 numbers using functions in cis swap a function in cswaping numbers in cwrite a program to swap values of two variableswrite an assemply program swap two numbershow to swap two numbers without third variableswap 2 numbers without 3rd variableswap two numbersc program to show interchange of two numbers using functions in c programmingwrite a function that swaps the values of two integerc function to swap two numbersc swap two variablesswap values cwrite a program in c to swap two numbers without using third variable swaping in cswap two numbers in cswapping by call by value in cswap elements in cswap program using 2 variablesswap using 3 variables in cswap by value in cswapping values in cc swap elements in arrayswap function inc cfunction swap in cswape values in cswap numbers without using third variable swap 2 numbers without using 3rd variableswap 2 number without using 3rd variablewrite a program to accept two numbers from user and swap their values define two numbers and swap valuesswap two digits in cswap using xor operator in cc program to swap two numberswrite a program to swap values of two variables with and without using third variable in how many ways we can swap two numbersswap the numbers in chow to swap two numberswrite a program to swap two integer values without using a third variable c swap integer bytrswrite a program that will make a swap between two defined variables using their addressesc swap two integersswap cswapping of two numbers without using third variable 28take input from user 29swap a numberswap by value function in chow to two value interchange in programming languagehow to swap a 2 digit numberswap values without using third variableswitching 2 variables in cc program exchange two numbersswapping number in cswap the values of two variables in cswap numbers code in cswitch 2 variables in cswap value without third variablewrite a program to swap two numberscreate a function that swaps the value of two integersswap using two variables in cswap to numers without 3rd variable 23include 3cstdio h 3e int swap 28int 2aa 2c int 2ab 29 7b 2aa 3d 2aa 2b 2ab 3b 2ab 3d 2aa 2ab 3b 2aa 3d 2aa 2ab 3b 27 7d int main 28 29 swapping of two numbers a 2bb 28a 3db 29write a program to swap any two no using third variable c 2b 2bcode for swapping two numbersswap in c languageswapping program in cdifferent ways of swapping two numberswhy can 27t you swap variables in cswapping of two numbers using 3 variableshow to swap in 3dswapping cfunction that swaps two integerswrite a function to swap two integers in cswap two number in cc how to make 2 variables swapc to swap how to swap structures in cswapping of two numbersc swap two variables functionswap the n numbers in cswap of two numbers in carray before swap and after swap programswapnumbers in c1 wap to swap the value of two variableprogram to swap two numbers in cswap two values using function in cswap with pointers in cc swap valueshow to swap variables in cswap 2 numbers without third variableswap numberswap fuction in c4 write a program to swap values of two integer variablesalgorithm to swap two numbers without using third variablehow to swap two digit in cdifferent method to swap the variables in c languageswap numbers in cswapping of variables in cwrite a program in c to swap two numbers without using a third variable swap varaibles cprogram to swap two numbers without using third variablewrite a program to swap two integer number without using third variable how to swap two values in a functionswap number in cc swap functionswap two number aroundwrite a program to swap the numbers in cprogram to swap two numbers 2 2c 3swaping a number in cswapping numbers without using 3rd variableswapping 2 numbers in chow to swap value in cswap values in c with two functionswap to swap the values of two variables using switch case c how to swap values with pointerwrite a program to swap two numbers without using a third 2ftemporary variablehow to swap numbersno of ways to swap two numberslogic to swap two numbershow to swap values in variables in cswapping of two numbers without using third variablec 2b 2b swap values without using third variableswap variable tempsc program to show interchange of two numbers in c programmingto swap the values of two integer numbers a and b entered by the user 2c and display the new numbers to the user do this with and without using a third variableswap variables in chow to swap three numbersswap the values of 2 given integer variables how to swap numbers in cswap function for integersswap using 2 variables cfunction to swap in cswap 2 numbers using call by valuewrite a program to swap values of two variables with using third variableswap two numbers with third variablewrite a program to input two unequal numbers display the numbers after swapping their values in the variables without using a third variable swaps example in programming languageswap value in c functionswap function in c programminghow to swap two numbers using functionsswap function in cswap two variables in cswap with two variables in cswap two number without third numberswrite a program to swap valueshow to swap numbers without using third variablecreate a function called swap that swaps the value of two integers it should work in place 2c actually modifying the integersvoid swap in cswap to numbers in c12 write a program to swap two numbers defining a function swap 28 29 write a program which asks the user to enter two integers a and b print the values the values are passed on to two functions which return the swapped values of a and b ways to swap two numbersswap 4 numbers in cswap values without third variable in cswap two numbers in c using functionswapping two numbers with third variableswap two integer function in cwrite a program to show swap of two numbers without using third variable swap numbers without using third variable in chow to swap two numbers without using a third variablewrite the programming code to swap two numbers without using the third variablefunction to swap two numbers in cswap number using 2 numberways of swap two numbershow to swap values in cwrite a program to swap the numbers in c programizswap function in c using pointersswapping elements in cswap value in cswap numbersswap program in cswap int cswap 2 variables in cwrite a program with a function named swap 28 29 that takes input in two variables a and b 2c and swaps their valuesswapping two numbers without using third variablehow to swap two numbers in cwrite a program on swaping two numbers with out using third variable 3fswap in c programmingprogram to swap two numbers without using the third variableswaping numbers using swap in ca 3d 2 2c b 3d 8 write a program to swap them without using third variables swap 2 numbers by using address function in cc programming to swap two variablesc different methods to swap 2 numberswrite a program for swapping of two numbers write a program to swap two numbers without taking a temporary variable how to use swap in cswap 2 numbers with using 3rd variableswapng two variable in cswap numbers without using third variableswap two var cswap two numbers functionswap two integers using function in cswaping function in cswap of two numbers using third variablecode to swap two numbersprogram to swap two numbers without using 3rd variable using bitwiseprogram to swap two numbersswapping logic in cprogramming questions like swap 2 numbers without 3rd variableswap the numbers using third variableswap numbers using function in cswapping in cwhat is swapping of two numbers workswap code in cswap 2 numbers in c programmingswap numbers in c from a functionwrite a function to swap the values between the variables in cswap variable in cexcahnge of integers with tem variable in cswap the value of two variables in cswapping two numbersmy swap in cswap logic in cwrite a program with a function to swap the values of 2 given integer variablesswap function cwrite a program to swap two numbers without using third variable swap program without using third variableswap two numbers without using third variablec swap intswrite a program to swap them without using third variables code for swapping two numbers in cswapping two variables in cwrite a program to swap two numbers without using temporary 2fthird variable program to swap two numbers without using 3rd variable swapping values in c without using third variablewrite a program to swap the values of three variables with using fourth variableswap two numbers without using a third variable 28 all possible ways 29 swap using function in cswaping chow to make a swap function with void 2ahow to define swap in cswap a number by 4 wayswrite a code to swap 2 number without using a 3rd variable 3fhow to swap variables without using a thid variable in c 2b 2bswap variable values in cprogram to swap two numbers