Showing posts with label divide. Show all posts
Showing posts with label divide. Show all posts

Friday, April 27, 2018

C program to perform mathematical operations


Program code
#include <stdio.h>
#include <conio.h>
void main()
{
 int num1, num2, option;
 clrscr();
 printf(“Please input two integers.\n”);
 scanf(“%d\n%d”,&num1,&num2);
 printf(“1. Add +\n2. Subtract -\n3. Multiply X\n4. Divide /\nPlease enter the number that is given near the operation you want to perform, in the above menu.\n”);
scanf(“%d”,&option);
switch(option)
{
case 1:printf(“%d + %d = %d”,a,b,a+b);
break;
case 2:printf(“%d - %d = %d”,a,b,a-b);
break;
case 3:printf(“%d X %d = %d”,a,b,a*b);
break;
case 4:printf(“%d / %d = %d”,a,b,a/b);
break;
default:
printf(“Invalid option”);
break;
}
getch();
}

Example of output
Please input two numbers.
67
78
1. Add +
2. Subtract –
3. Multiply X
4. Divide /
Please enter the number that is given near the operation you want to perform, in the above menu.
1
67 + 78 = 145