Write a program to swap two numbers using command line programming

C Programming Language / Command Line Arguments

3513

Program:

// 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;
}

Output:

10 12


After swapping, firstNumber = 12.00
After swapping, secondNumber = 10.00

Explanation:

Nope

This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.