Command Line Program for Swapping two Numbers
Ques. Write a program to swap two numbers using command line programming?
It is highly advisable to go through Command Line Arguments Post before even looking at the code. Please study this for TCS and come back to this post later.
[code language=”cpp”]
#include<stdio.h> #include<math.h> #include<stdlib.h> int main(int argc, char * argv[]) { if(argc==1){ printf("No command line argument present, add them first"); return 0; } double firstNumber, secondNumber, temporaryVariable; firstNumber = atoi(argv[1]); secondNumber = atoi(argv[2]); temporaryVariable = firstNumber; firstNumber = secondNumber; secondNumber = temporaryVariable; printf("\nAfter swapping, firstNumber = %.2lf\n", firstNumber); printf("After swapping, secondNumber = %.2lf", secondNumber); return 0; }
[/code]
Other TCS Coding Questions –
- TCS Coding Questions – 1
- TCS Coding Questions – 2
- Area of a Triangle
- TCS Command Line Arguments – Fibonacci Series
- TCS Command Line Program to Swap two numbers
- TCS String Reversal Using Command Line Programming
- Greatest of Two Numbers using CLP
- LCM of Two Number using CLP
- Average of Two Numbers
- Sum of Digits of a number
- Binary to Decimal
- Decimal to Binary
- Factorial of a Number
- Square Root of Prime Number
- Armstrong Number
Login/Signup to comment
command line