Make a Calculator using C Programming Language: TheTodayBlog

Rate this post

Learn How To Make Calculator using C Programming Language – The Today Blog

Well what is a calculator, and what are its uses. I think I do not have to tell you. but have you ever thought about that how a calculator is made? can we also make a calculator by using programming language? yes, you can make your own calculator, it is very easy.

calculator in c programming

in this article, I will tell you how you can make a calculator in easy ways by using the programming language. so for making a calculator in C programming we will use a switch statement. In computer programming languages, a switch statement is a type of selection control mechanism used to allow the value of a variable or expression to change the control flow of program execution via search and map. A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each switch case.

Syntax of Switch Statement:-

switch( expression )
{
	case value-1:
			Block-1;
			Break;
	case value-2:
			Block-2;
			Break;
	case value-n:
			Block-n;
			Break;
	default:
			Block-1;
			Break;
}
Statement-x;

make calculator in c

Programming for Calculator:

for making a calculator in C language we need a software named Turbo c++

#include< stdio.h >
#include< conio.h >
main()
{
clrscr();

float num1;
float num2;
char op;

float result;
printf("Enter the First Number:");
scanf("%f",&num1);
printf("Enter the Operation: ");
scanf(" %c",&op);

Do not forget to add space before percent otherwise the character value will not be executed.

 
printf("Enter the Second Number:");
scanf("%f",&num2);
switch(op)
{
case '+':

result = num1+num2;
printf(“%f”,result);
break;

case '*':
result = num1*num2;
printf(“%f”,result);
break;

case '-':
result = num1-num2;
printf(“%f”,result);
break;

case '/':
result = num1/num2;
printf(“%f”,result);
break;

default :
printf("The Operation is not valid");
}
getch();
}
c programming

By using these programs you can easily make calculators in c programming.

READ ALSO: TOP 5 MUST WATCH WEB SERIES ON NETFLIX that You Cannot Afford To Miss: The Today Blog

Follow us on Twitter and Facebook also.

Follow me personally on Instagram and Twitter.

28 thoughts on “Make a Calculator using C Programming Language: TheTodayBlog”

Leave a Comment