Subscribe to:
Post Comments (Atom)
/*
* 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
0 comments:
Post a Comment