C Program to Add, Subtract, Divide, Multiply Two Numbers

Write a C program to perform arithmetic operations addition, subtraction, division and multiplication of two numbers.

C program to perform arithmetic operations on two numbers

/* Aim: Accept two numbers in variables x and y from the user and perform different operations */

#include<stdio.h>

int main()
{

	char ope;
	int a,b,add,sub,div,prod;
 
	printf("\n Enter any operator from (+,-,/,*):- ");
	scanf("%c",&ope);

	printf("\n Enter any two numbers:- ");
	scanf("%d%d",&a,&b);

	switch(ope)
	{ 
	case '+':
	add=a+b; 
	printf("\n The sum of %d and %d is %d \n \n",a,b,add);
	break;

	case '-':
	sub=a-b;
	printf("\n The subtraction of %d and %d is %d \n \n",a,b,sub);
	break;
 
	case '/':
	div=a/b;
	printf("\n The division of %d and %d is %d \n \n",a,b,div);
	break;

	case '*':
	prod=a*b;
	printf("\n The product of %d and %d is %d \n \n",a,b,prod);
	break;
 
	default:
	printf("\n You haven made invalid choice \n \n");
	}

	return 0;
}

Output:

 Enter any operator from (+,-,/,*):- *

 Enter any two numbers:- 1 1 

 The product of 1 and 1 is 1