Math, asked by pooja2903, 7 months ago

Write a program to swap values of two variables by using third variable.
TI​

Answers

Answered by simra4825
12

Answer:

HEY MATE HERE'S YOUR ANSWER

Step-by-step explanation:

ariable

1. Declare three variables.

2. i) Assign the value of the first variable in temp.

ii) Then assign the value of the second variable into the first variable.

iii) Finally, assign the value of temp variable into the second variable.

Let’s declared three variables temp, a and b. Code logic to swap two numbers using third variable.

  1. //Logic to swap two numbers using third variable
  2. temp = a;
  3. a = b;
  4. b = temp;

C Program to swap two numbers without using third variable

Swap two numbers using a pointer

Swap two numbers using bitwise XOR operator

Programming questions on various topics for practice

We have understood how to swap two numbers using third variable. Let’s write a c code to implement them.

  1. #include <stdio.h>
  2. int main(void)
  3. {
  4. // Variable declaration
  5. int a, b, temp;
  6. printf("Enter two numbers a and b ");
  7. scanf("%d %d", &a, &b);
  8. // Swap logic
  9. temp = a;
  10. a = b;
  11. b = temp;
  12. printf("\n After swapping \na = %d\nb = %d\n", a, b);
  13. return 0;
  14. }

C, C++ Programming Questions for Practice

HOPE IT WILL HELP YOU PLZ MRK AS BRAINLIST.

DON'T FORGET TO FØLLØW ME

HV A GOOD DAY

Similar questions