Day 4 Training:
control statements/Decision Making:
if(Condition) if(condition) else if else if(condition)
if(cond) if(cond)
{ { if(cond)
{
} } }
else else if(cond2)
{ {
} }
else if(cond3)
{
}
else
{
}
Write a program for Calculator in C:
#include <stdio.h>
int main()
{
char op;
int num1;
int num2;
printf("What you wanted to do\n");
scanf("%c",&op);
printf("enter two numbers\n");
scanf("%d",&num1);
scanf("%d",&num2);
printf("%d\n",num1);
switch(op){
case '+':
printf("sum= %d",num1+num2);
break;
case '-':
printf("Subtraction= %d",num1-num2);
break;
case '%':
printf("Reminder= %d",num1%num2);
break;
case '/':
printf("Division= %d",num1/num2);
break;
default:
printf("Nothing");
}
}
0 Comments