Written by Sai Sandeep Thota on April 11, 2013 in C > C++ > Programming

C / C++ Program to perform Arithmetic Operations

GET ALERTS:

Get our Latest updates delivered to your mailbox!

This is a simple C and C++ program to perform Arithmetic Operations like Addition, Subtraction, Multiplication, Division and for finding Remainder of two given integers. This program uses a Switch-case to determine which operation to perform.

C Program to perform Aruthmetic Operations

#include<conio.h>
#include<stdio.h>
#include<process.h>

void main()
{
	int a, b, result, ch;
	clrscr();
	do {

		printf("\nEnter Two Integers:");
		scanf("%d %d",&a,&b);
		printf("\n1.Add\n2.Subtract\n3.Multiply\n4.Divide\n5.Remainder\n6.Exit");
		printf("\nEnter your Choice:");
		scanf("%d",&ch);
		switch(ch)
		{
			case 1: result=a+b;
				printf("\nAddition: %d", result);
				break;
			case 2: result=a-b;
				printf("\nSubtraction: %d", result);
				break;
			case 3: result=a*b;
				printf("\nMultiplication: %d", result);
				break;
			case 4: result=a/b;
				printf("\nDivision: %d", result);
				break;
			case 5: result=a%b;
				printf("\nRemainder: %d", result);
				break;
			case 6: exit(1);
			default: printf("\nEnter a valid choice!");
		}
	}while(1);
}

C++ Program to perform Arithmetic Operations

#include<conio.h>
#include<iostream.h>
#include<process.h>

void main()
{
	int a, b, result, ch;
	clrscr();
	do {

		cout<<"\nEnter Two Integers:";
		cin>>a>>b;
		cout<<"\n1.Add\n2.Subtract\n3.Multiply\n4.Divide\n5.Remainder\n6.Exit";
		cout<<"\nEnter your Choice:";
		cin>>ch;
		switch(ch)
		{
			case 1: result=a+b;
				cout<<"\nAddition: "<<result;
				break;
			case 2: result=a-b;
				cout<<"\nSubtraction: "<<result;
				break;
			case 3: result=a*b;
				cout<<"\nMultiplication: "<<result;
				break;
			case 4: result=a/b;
				cout<<"\nDivision: "<<result;
				break;
			case 5: result=a%b;
				cout<<"\nRemainder: "<<result;
				break;
			case 6: exit(1);
			default: cout<<"\nEnter a valid choice!";
		}
	}while(1);
}

Output:
c-cpp-arithmetic-operations

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: