Sunday 15 December 2013

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");
}

Output

  5   4  +
arguments entered:
5 4 +
The result of the operation is 9
8 7 -
arguments entered:
8 7 -
The result of the operation is 1
9 6 x
arguments entered:
9 6 x
The result of the operation is 54
100 10 /
arguments entered:
100 10 /
The result of the operation is 10

For More Details Please Visit Ictjobs.info

No comments: