Q:

C Program to swap two numbers using a third variable or temp variable

belongs to collection: C Programming on Numbers

0

You can easily swap two numbers using the third variable. see the below concept.

Step1:
temp = var1;
 
Step2:
var1 = var2;
 
Step3:
var2 = temp;

All Answers

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

#include <stdio.h>
int main()
{
    int a, b,tmp;
    
    printf("Enter Value of a = ");
    scanf("%d", &a);
    printf("Enter Value of b = ");
    scanf("%d", &b);
    temp = a;
    a = b;
    b = temp;
    printf("\nAfter Swapping: a = %d, b = %d", a, b);
    return 0;
}

Output:

Enter Value of a = 10
Enter Value of b = 20

After Swapping: a = 20, b = 10

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

total answers (1)

C Programming on Numbers

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C Program to find given number is sum of first n n... >>
<< C Program to find given number is the sum of first...