P175. Design a calculator with command line arguments.
#include<stdio.h>
#include<stdlib.h>
void
main(int argc,char **argv)
{
if(argc!=4)
printf("Enter valid
arguments");
int n1,n2;
n1=atoi(argv[1]);
n2=atoi(argv[3]);
switch(argv[2][0])
{
case '+' : printf(" Sum =
%d",n1+n2);
break;
case '-' : printf(" Sub =
%d",n1-n2);
break;
case '*' : printf(" Mul =
%d",n1*n2);
break;
case '/' : printf(" Div =
%d",n1/n2);
break;
}
}
Comments
Post a Comment