Q:

C program to swap two numbers

0

C program to swap two numbers

 

C program to swap two numbers with and . If the program has two variables a and b where a = 4 and b = 5, after swapping them, a = 5, b = 4. In the first C program, we use a temporary variable to swap two numbers.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>
int main()
{
  int x, y, t;

  printf("Enter two integers\n");
  scanf("%d%d", &x, &y);

  printf("Before Swapping\nFirst integer = %d\nSecond integer = %d\n", x, y);

  t = x;
  x = y;
  y = t;

  printf("After Swapping\nFirst integer = %d\nSecond integer = %d\n", x, y);

  return 0;
}

The output of the program:
Enter two integers
23
45
Before Swapping
First integer = 23
Second integer = 45
After Swapping
First integer = 45
Second integer = 23

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now