BACK TO 10+2 STEM LAB
10+2 MATHEMATICS & DRAWINGS•2016-06-04•4 MIN READ

C program to perform basic arithmetic addition, subtraction, multiplication and division

C program to perform basic arithmetic operations which are an addition, subtraction, multiplication, and division of two numbers. Numbers are assumed to be integers and will be entered by the user.

Key Architecture Takeaways

  • ›
    Point 1: Core computer science and engineering computing concept: C program to perform basic arithmetic addition, subtraction, multiplication and division.
  • ›
    Point 2: Detailed trace of memory representation, algorithmic complexity, and control structures.
  • ›
    Point 3: Includes portable ISO C (C17/C23) code examples verified with modern GCC and Clang.
Notice

Compiler & Toolchain Modernization

While legacy educational environments used 16-bit DOSBox Turbo C++, all code presented here adheres to standard ANSI/ISO C standards. You can compile these programs cleanly on modern Linux, Windows (MSYS2/WSL), or macOS using:

bash
> gcc -Wall -Wextra -O2 program.c -o program
> ./program
> ```


---

C program to perform basic arithmetic operations which are an addition, subtraction, multiplication, and division of two numbers. Numbers are assumed to be integers and will be entered by the user.

<article id="node-218" class="node node-page node-full clearfix">

## C programming code to perform basic arithmetic:

In this program calculate all basic arithmetic operation based on user's input values and display the result of those operations as output.

c

#include <stdio.h> int main() { int a, b, add, subtract, multiply; float divide; //*divide variable declare as float because // the result may come in fraction. printf("Enter two integers\n"); scanf("%d%d", &a, &b); add = a + b; subtract = a - b; multiply = a * b; divide = a / (float)b; //typecasting printf("Sum = %d\n",add); printf("Difference = %d\n",subtract); printf("Multiplication = %d\n",multiply); printf("Division = %.2f\n",divide); return 0; }

SHELL
Output of program:

In C language when we divide two integers, we get integer result for example 5/2 evaluates to 2. As a general rule integer/integer = integer and float/integer = float or integer/float = float. So we convert denominator to float in our program, you may also write float in the numerator. This explicit conversion is known as typecasting.

**C program that takes two number from the user then performs basic arithmetic as user's choice.**

In this program, we use conditional if function to perform basic arithmetic as user's choice. After putting two values the user can choose one of four basic arithmetic operators to perform the operation.

c

#include <stdio.h> int main() { int a, b, add, subtract, multiply; float divide; //*divide variable declare as float because char c; // the result may come in fraction. printf("Enter two integers\n"); scanf("%d%d", &a, &b); printf("Enter your Choice (+,-,,/) :"); c=getch(); if (c=='+') { add = a + b; printf("Sum = %d\n",add); }elseif(c=='-') { subtract = a - b; printf("Difference = %d\n",subtract); }elseif(c=='') { multiply = a * b; printf("Multiplication = %d\n",multiply); }elseif(c=='/') { divide = a / (float)b; //typecasting printf("Division = %.2f\n",divide); } getch(); return 0; }

SHELL
output:

[![basic arithmetic](http://technhit.in/wp-content/uploads/2016/06/basic-arith.jpg)](http://technhit.in/wp-content/uploads/2016/06/basic-arith.jpg)

## C Program to find area and circumference of circle:

In this program, we have to calculate the area and circumference of the circle. We have following 2 formulas for finding circumference and area of the circle. Area of Circle = PI * R * R and Circumference of Circle = 2 * PI * R

c #include<stdio.h>

int main() {

int rad; float PI = 3.14, area, ci; clrscr();

printf("\nEnter radius of circle: "); scanf("%d", &rad);

area = PI rad rad; printf("\nArea of circle : %f ", area);

ci = 2 PI rad; printf("\nCircumference : %f ", ci); getch();

return (0); }

SHELL
Output:

[![area of circle](https://www.technhit.in/wp-content/uploads/2016/06/area-of-circle.png)](https://www.technhit.in/wp-content/uploads/2016/06/area-of-circle.png)

## Program to convert temperature from degree centigrade to Fahrenheit:

We know that the temperature *T* in degrees Fahrenheit (°F) is equal to the temperature *T* in degrees Celsius (°C) times 9/5 plus 32:

*T*<sub>(°F)</sub> = *T*<sub>(°C)</sub> × 9/5 + 32

or

*T*<sub>(°F)</sub> = *T*<sub>(°C)</sub> × 1.8 + 32

c #include<stdio.h> int main() { float celsius, fahrenheit; clrscr();

printf("\nEnter temp in Celsius : "); scanf("%f", &celsius);

fahrenheit = (1.8 * celsius) + 32; printf("\nTemperature in Fahrenheit : %f ", fahrenheit); getch();

return (0); } ```

Output: As we know that in -40° both Centigrade and Fahrenheit are equal.

centigrade to Fahrenheitcentigrade to Fahrenheit

##

</article>

π
TechNHIT STEM Faculty
Department of Applied Mathematics & Physics
C program to perform basic arithmetic addition, subtraction, multiplication and division | TechNHIT 10+2 STEM Lab | TechNHIT