Learning Objectives: The objective of this exercise is to get you to write, compile and run a
number of simple programmes in C.
#include<stdio.h>
#include<conio.h>
int main(){
int a,b;
char dec;
a=b=0;
dec=0;
/* variable deceleration and initialization */
printf("***Simple Arithmetic Operation Calculator***\n");
printf("***======================================***\n\n");
/* headings */
printf("Enter any Number\n");
scanf("%d",&a);
printf("\nEnter another Number\n");
scanf("%d",&b);
/* Numbers input */
printf("\nInstruction:\n");
printf("============\n");
printf("Press + for Addition\n");
printf("Press - for Substraction\n");
printf("Press * for Multiplication\n");
printf("Press / for Division\n");
printf("Press M for Reminder\n");
dec=getch();
/* operation decion by user */
switch(dec){
case '+':
printf("\n\nAnswer %d",a+b);
break;
case '-':
printf("\n\nAnswer %d",a-b);
break;
case '*':
printf("\n\nAnswer %d",a*b);
break;
case '/':
if(b==0)
printf("\n\nDividing by zero ERROR!!!");
else
printf("\n\nAnswer %d",a/b);
break;
case 'M':
case 'm':
printf("\n\nAnswer %d",a%b);
break;
default:
printf("\n\nInvalid Input..!!!");
}
/* Switch function contains processing of operations */
getch();
return 0;
}
No comments:
Post a Comment