50 C Program to Input 3 Arguments and Operate Appropriately on the Numbers
Posted by Superadmin on December 24 2015 02:18:18
This C Program input 3 arguments and operate appropriately on the numbers.
Here is source code of the C Program to input 3 arguments and operate appropriately on the numbers. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

/*
* C Program to Input 3 Arguments and Operate Appropriately on the
* Numbers
*/
#include <stdio.h>

void main(int argc, char * argv[])
{
int a, b, result;
char ch;

printf("arguments entered: \n");
a = atoi(argv[1]);
b = atoi(argv[2]);
ch = *argv[3];
printf("%d %d %c", a, b, ch);
switch (ch)
{
case '+':
result = a + b;
break;
case '-':
result = a - b;
break;
case 'x':
result = a * b;
break;
case '/':
result = a / b;
break;
default:
printf("Enter a valid choice");
}
printf("\nThe result of the operation is %d", result);
printf("\n");
}

$ gcc arg2.c
$ a.out 5 4 +
arguments entered:
5 4 +
The result of the operation is 9
$ a.out 8 7 -
arguments entered:
8 7 -
The result of the operation is 1
$ a.out 9 6 x
arguments entered:
9 6 x
The result of the operation is 54
$ a.out 100 10 /
arguments entered:
100 10 /
The result of the operation is 10