{{#items}}

{{text}}

{{/items}} {{ctaText}}

{{#items}} {{/items}}

showing results for - "swap two var c"

Mila

23 Apr 2020

```
1#include <stdio.h>
2int main() {
3 double a, b;
4 printf("Enter a: ");
5 scanf("%lf", &a);
6 printf("Enter b: ");
7 scanf("%lf", &b);
8
9 // Swapping
10
11 // a = (initial_a - initial_b)
12 a = a - b;
13
14 // b = (initial_a - initial_b) + initial_b = initial_a
15 b = a + b;
16
17 // a = initial_a - (initial_a - initial_b) = initial_b
18 a = b - a;
19
20 printf("After swapping, a = %.2lf\n", a);
21 printf("After swapping, b = %.2lf", b);
22 return 0;
23}
24
```

Emilie

29 Apr 2018

```
1#include <stdio.h>
2int main()
3{
4 int a, b, temp;
5 printf("enter the values of a and b: \n");
6 scanf("%d%d", &a, &b );
7 printf("current values are:\n a=%d\n b=%d\n", a, b);
8 temp=a;
9 a=b;
10 b=temp;
11 printf("After swapping:\n a=%d\n b=%d\n", a, b);
12}
```

Alessio

17 Feb 2018

```
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
```

Ivanna

05 Mar 2020

```
1#include <stdio.h>
2
3int main()
4{
5 int a = 10;
6 int b = 5;
7
8 //swap start
9 a = a + b; //a = 10 + 5 = 15
10 b = a - b; //b = 15 - 5 = 5
11 a = a - b; //a = 15 - 5 = 10
12
13 printf("a = %d / b = %d\n", a, b);
14 //a = 5 / b = 10
15 return 0;
16}
17
18
19/*You can create a function*/
20
21void swap(int *a, int *b)
22{
23 *a = *a + *b; //a = 10 + 5 = 15
24 *b = *a - *b; //b = 15 - 5 = 5
25 *a = *a - *b; //a = 15 - 5 = 10
26}
27
28int main()
29{
30 int a = 10;
31 int b = 5;
32
33 //call with adress of the var
34 swap(&a, &b);
35 printf("a = %d / b = %d\n", a, b);
36 //a = 5 / b = 10
37 return 0;
38}
```

similar questions

swap using third variablec programming to swap two variablesswap without using third variablec program to swap two arraysc function to swap two numbersc flip variableswap two numbers in cc program to swap two numbers using call by referenceswitch statement in cprogram to swap two numbersqueries leading to this page

c ode to swap 2 numbersswap function in cswap two numbers in c without using third variableswap function to swap two numbers in array in cswapping two variables without temp in cswap two numbers without using third variable in cswap function in cswap the value in chow to swap two numbersbest way to swap two variables without using temp in cswap two values using function in chow to swap value in chow to swap two numbers in carray before swap and after swap programswapping in cswap the values of 2 given integer variables swapping values in cswapping without third variable in cswap the numbers in cwrite down a program in c for swapping of two numbers using 2a and 2f operatorswap values of two variables without using third variable in cswap variables in cswaping numbers in cswapping cswap two numbers without third variable in cfunction to swap in cswap the value of given number in cwrite a c program to swap two numbersswap function cswap in c programmingswapping 3 numbers in cswapping of two numbers without using third variable in cswap number in cswap two integers using function in cswapping without temporary variable in cswap 2 numbers by using address function in chow to swap numbers in chow to swap 4 number in cswap values in c exampleswap the two numbers in cswap function for integersvoid swap in cswap value without third variable in chow to swap two digit in cprogram to swap two numbers in cswapping two numbers in c using mathematical expressionswap 2 numbers using functions in cfunction to swap two numbers in cswap program in cc program to swap two numbers using and without using third variablewrite a c program to swap these two numbers swap program in c without using third variableswap values without third variable in chow to make a swap function with void 2afunction that swaps two integersswap two user given integerc program to swap two numbers using functionsc swap two variables functionwrite a program to swap two numbershow to swap variables in cc program to swap values of two variables using third v ariableswap every two number of an integers in cswap two numbers using bitwise operator in cc to swap swap cwrite a program that will make a swap between two defined variables using their addressesc swap functionhow to use swap in cswapping two variables in cswap in c languageswapping program in cswap 4 numbers in chow to swap in 3dswap two numbers c programswap of 2 numbers in cswap two number in cc program to swap two numbers using function call by valueswap function code in cswapnumbers in cswitching 2 variables in chow to swap cwrite a program with a function to swap the values of 2 given integer variablesswap two numbers without using bitwise in cswap logic in chow can we swap in cwrite a c program to swap two numbers with function without arguments and without return valueswaps example in programming languageswap with two variables in cswapping of two variables in cswap program using 2 variablesswap two numbers using function in cswapping two numbers in cc program to swap two numbers without using third variablec program to show interchange of two numbers using functions in c programmingwrite a c program to swap two numbers c function without arguments and without return valueswap numbers without using third variable in cwrite a programme to swap two numbers in cswap of two numbers in cc code to swap two numberswrite a programme to swap two numbers using thirdveriable in cswapping number in chow to swap two values in a functionswap two numbers function in cswap two integers without using third variable in cswap using 3 variables in cswap two var cc swap integer bytrsswap c functionexcahnge of integers with tem variable in cswapping logic in cswapping of two numbers in chow to swap two numbers in c without using third variableswping two numbersswapping by call by value in cwrite a program to swap the numbers in c programizc program to swap three numbers using fourth variableswap two numbers using predefined variable c programswap int cwrite a program to swap two numbers in c programswap numbers using function in cc program swapping without using third variableswap the number using macro in cswap 2 numbers in c programmingswap numbers in c from a functionswapping of two numbers in c using functionsswap using 2 variables cwrite a program to swap 2 numbers without thirdvariable in cswap 3 numbers in cswapping of variables in cswap 2 numbers in ccode for swapping two numbers in cswap values cswap numbers code in cwrite a c program to swap two numbers using third variablewrite a c program to check a swapswap values in cswap the value of two variables in cswap 2 variables without temp in cswap 2 number cc program to swap two numbers without a third variablec function to swap two numbers using bitwise operation swapping numbers in cc program to swap two numbers using call by valuec swap intsswap 2 numbersswap two numbers in c using call by referenceswap code in cc function to swap two numbersswap 2 numbers without using 3rd variable in cwrite 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 swap of two numbers using third variablefunction swap in cc different methods to swap 2 numberswrite a program to swap 2 numbers without third variable in cswaping c c program to swap two number without using third variablewrite a program to swap the numbers in chow to swap three numbers in cswapping of two numbers in c logicc how to swap values with pointerswap two variables in cswap numbers c swap to numbers in cwhy can 27t you swap variables in cswaping function in cswap varaibles cswaping in cswap with pointers in cswape values in cswap two structures in cswap two digits in cwrite a program for swapping of two numbers swapping number c programmingwrite down a program in c for swapping of two numbers using 2b 2f operatorc program for swapping of two numbers using temporary variablec swap two integersswapping elements in cc swap elements in arrayswap two numbers without using temporary variable in cswap in cswapping 2 numbers in cswap numbers in chow to swap values in variables in cswap by value in ccreate a function that swaps the value of two integersswapping two numbers in c without using bitwise operatorswrite a c program to swap two numbers without using third variable c program to swap two numbers without a third variable using conditionalswap to swap the values of two variables using switch case swap two integer function in cswapping two number different type of method in cswap using function in cswapping of two numbers in c without temporary variableswap the n numbers in cswapping of two numbers in c using functionswap two variablesswapping with permanent number in cwrite a function to swap the values between the variables in cconsider this c code to swap two integers and these five statements 3a the codeswapping two values in cswap to number without using 3rd variable in cswap using xor operator in cprogram to swap two numbershow to swap values in cprogram to swap two values in cswap 2 numbers using call by reference in cc program for swapping of two numbersc program to swap three numbersswap variable in cswap two bit in cswap variable tempsswap elements in cswap variable values in cswap without third variable in cswap every two integers in cswapping of two numbers in c in single lineswap using two variables in cswap tow number in cswap two integers without using temporary variable in cswap without third variable cswap function in c using pointers1 wap to swap the value of two variablewrite a program to accept two numbers from user and swap their values c swapswapping of two numbersprogram to swap digits within a number cswap digits in a number cswap 2 variables without using 3rd variable in chow to swap two variables without third variable in cswap by value function in cswap values in c with two functionsswaping numbers using swap in cc program to show interchange of two numbers in c programmingcode for swaping two numbers in c using pointersswap 2 variables in cwrite a c program to swap two given numbers using call by reference swapping of two numbers in c by call by reference in chow to swap structures in cc how to make 2 variables swapswap to nos in cswapping of two numbers in c without thirdvariableswap the value in c using functionmy swap in cc program exchange two numbershow to swap two numbers in c using functionc programming to swap two variablesc swap two variablesc program to swap two numbersswapping two numbers program in cswitch 2 variables in cswap the values of two variables in cswap function inc cwrite a function to swap two integers in chow to swap two integers in ccode for swapping of two numbers without using temporary variable using c swap fuction in cswap 2 number in cswap function in c programmingswap two numbers in cc program to interchange two numbersswapping of two no using function in cswapng two variable in cc program to swap two noswrite down a program in c for swapping of two numbers using bitwise operatorswrite a program in c to swap two numbers using the function swap numbers in chow to define swap in cadding two digit numbers and swap in cswapping of two numbers in c using 2 variablesswap in c without temporary variableswapping with temporary variable in cswapping variable values in cswapping values in c without using third variableuse of swap in c how to swap two numbers in c using arraysc program to swap two numbers without using third variable write down a program in c for swapping of two numbers a 29 using 2b 2f operatorc swap valuesis swap a function in cswap two numbers in c using functionc swap to variablesdifferent method to swap the variables in c languageswaping a number in cswap two var c your answer for

you will get a confirmation link on this - you will have to click that for successful submission of your answer. we require this to keep the website free of spam, bots and unhelpful content

please ensure to add code which is syntactically corrent and executes properly

ask question on maxinterview

you will get a confirmation link on this - you will have to click that for successful submission of your question. we require this to keep the website free of spam, bots and unhelpful content

please be clear, to the point and respectful