Write a program to swap two numbers using the third variable.
C Program
#include <stdio.h>int main(){int firstNum, secondNum;printf("Enter first number : ");scanf("%d", &firstNum);printf("Enter second number : ");scanf("%d", &secondNum);printf("Numbers before swap is first= %d, second= %d\n", firstNum, secondNum);int thirdNum = firstNum;firstNum = secondNum;secondNum = thirdNum;printf("Numbers after swap is first= %d, second= %d\n", firstNum, secondNum);return 0;}
Input:
Enter first number : 10
Enter second number : 20
Output:
Numbers before swap is first= 10, second= 20
Numbers after swap is first= 20, second= 10
No comments:
Post a Comment