## Calculator program in C

#include <stdio.h> int main () { char operator; printf("enter the operator (+ - * /)\n press A for Area of circle\n press B for circumference of circle \n press C area of rectangle\n"); scanf("%c",&operator); double first,second,area; printf("enter two numbers one by one= "); scanf("%lf %lf",&first,&second); if (operator=='+') { printf("The sum is=%.3lf",first+second); } else if(operator=='-'){ printf("The subtration is=%.3lf",first-second); } else if(operator=='*'){ printf("The multiplication is=%.3lf",first*second); } else if(operator=='/'){ printf("The division is=%.3lf",first/second); } else if(operator=='a'){ area =3.1416*first*second; printf("Area of circle is%.3lf",area); } else if(operator=='b') { area =2.0*3.1416*first; printf("circumference of circleif is%.3lf",area); } else if(operator =='c'){ area=first*second; printf("area of rectangle is%.3lf",area); } }

## Calculator program in C code explanation

This code is a C program that performs basic arithmetic operations and calculates the area of a circle and rectangle based on user input. Let’s go through the code step by step:

- The code starts by including the standard input/output library (
`stdio.h`

) which provides functions for input and output operations. - The
`main()`

function is the entry point of the program. - It declares a character variable called
`operator`

to store the user’s choice of operation. - The program prompts the user to enter the operator choice by displaying a menu of options, including options for the area of a circle, circumference of a circle, and area of a rectangle.
- The
`scanf()`

function is used to read the character input from the user and store it in the`operator`

variable. - The program declares three variables:
`first`

,`second`

, and`area`

. These variables are of type`double`

to store decimal numbers. - The program prompts the user to enter two numbers one by one using the
`printf()`

function. - The
`scanf()`

function is used again to read two decimal numbers from the user and store them in the`first`

and`second`

variables. - The program uses a series of
`if`

and`else if`

statements to determine the operator entered by the user and perform the corresponding operation or calculation.- If the operator is
`+`

, it calculates the sum of`first`

and`second`

using the`+`

operator and prints the result using`printf()`

. - If the operator is
`-`

, it calculates the subtraction of`second`

from`first`

using the`-`

operator and prints the result. - If the operator is
`*`

, it calculates the multiplication of`first`

and`second`

using the`*`

operator and prints the result. - If the operator is
`/`

, it calculates the division of`first`

by`second`

using the`/`

operator and prints the result. - If the operator is
`a`

, it calculates the area of a circle using the formula`3.1416 * first * second`

and stores the result in the`area`

variable. Then it prints the area of the circle. - If the operator is
`b`

, it calculates the circumference of a circle using the formula`2.0 * 3.1416 * first`

and stores the result in the`area`

variable. Then it prints the circumference. - If the operator is
`c`

, it calculates the area of a rectangle using the formula`first * second`

and stores the result in the`area`

variable. Then it prints the area of the rectangle.

- If the operator is
- The code does not handle cases where the user enters an invalid operator.
- The
`main()`

function does not have a`return`

statement, so it implicitly returns 0, indicating successful execution of the program.

Overall, this program allows the user to perform basic arithmetic operations and calculate the area of a circle or rectangle based on their choice of operator.