C Programming to implement calculator

VIGNESWARAN.S
4 min readJun 3, 2021

If you are a bio maths student,don’t worry.This blog will help you .It is useful for all the students.I have used simple ENGLISH for your understand purpose.I have given clear information about calculator programming.This program is in first year lab exercise for ENGINEERING students.

Aim for this program

To design a simple calculator in C programming using the switch statement.

Concepts Involved in this program

Data types:

Data type specifies the type of data that a variable can store such as integer, floating ,character ,etc……..

In this program ,we have used int and char data type .

int

An int variable is used to store an integer

syntax for int:

int variable_name =integer ;

For eg: int a=10;

char

The most data type in c. It stores a single byte of a memory in almost all compilers.

syntax for char:

char variable_name=”single character”;

char b=”x”;

Switch statements

A Switch statement allows a variable to be tested for quality against a list of values.Each value is called a case and the variable being switched on is checked fore each switch case.

syntax for switch:

switch(expression)

{

case value1:

statement(s);

break;

case value2:

statement(s);

break;

…….

default:

statement(s)

}

Algorithm for this program

Step1:Start

Step2:declare variable n,a,b,c of int data type

Step3:display the menu to the user

Step4:read the value of n from user

Step5:if the user enter any number from 1 to 5 the follow the steps

Step6:a.case1: read the values of a and b .The sum of a and b .Display the result .break;

b.case2:read the value of a and b .The subtraction of a and b .Display the result. break;

c.case3:read the value of a and b .The multiplication of a and b .Display the result. break;

d.case4:read the value of a and b .The division of a and b .Display the result. break;

e.case5:read the value of a and b .The square of a .Display the result. break;

f.default:display ‘Invalid’

Step7:stop

FLOWCHART

Explanation

What is#include<stdio. h> ?

The header file stdio. h stands for Standard Input Output. It has the information related to input/output functions

What is #include<conio. h>?

#include<conio. h> It is a header file used in c and it includes inbuilt functions like getch() and clrscr(). It stand for console input ouput i.e. it takes input from keyboard and displays it on screen

What is main ?

main() function is the entry point of any C program. It is the point at which execution of program is started. When a C program is executed, the execution control goes directly to the main() function. Every C program have a main() function.

What is printf and scanf ?

The printf() function is used to display output and the scanf() function is used to take input from users. The printf() and scanf() functions are commonly used functions in C Language. These functions are inbuilt library functions in header files of C programming.

What is switch and case ?

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.

What is break statement ?

The break is a keyword in C which is used to bring the program control out of the loop. The break statement is used inside loops or switch statement. The break statement breaks the loop one by one, i.e., in the case of nested loops, it breaks the inner loop first and then proceeds to outer loops.

Why default is used in C?

Switch case statements are used to execute only specific case statements based on the switch expression. If switch expression does not match with any case, default statements are executed by the program.

What is ruturn 0?

return 0 in the main function means that the program executed successfully. return 1 in the main function means that the program does not execute successfully and there is some error. return 0 means that the user-defined function is returning false. return 1 means that the user-defined function is returning true

Program\Source code

EXECUTED OUTPUT

SUCCESFULLY WE HAVE EXECUTED THE OUTPUT FOR THIS PROGRAM

I hope it’s useful and easy to you

For any reference :

You can learn C and other languages clearly in GUVI.

--

--