You can easily swap two numbers using the third variable. see the below concept.
#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 = 10Enter Value of b = 20
After Swapping: a = 20, b = 10
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
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