// Program by atnyla
// A program to swap two numbers using command line programming
#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;
}
10 12
After swapping, firstNumber = 12.00
After swapping, secondNumber = 10.00
First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.