addition

C Program to Addition Subtraction,Multiplication and division

C Program to Addition Subtraction, Multiplication and division

In this tutorial, we will discuss C Program to Addition Subtraction, Multiplication and division

C Program to Arithmetic operation

In this post, we will learn about how to perform addition, subtraction multiplication, division of any two numbers  using if else statements in C programming

The  program will request the user to enter two number digits and the user select an operator to perform the addition, subtraction, multiplication, and division of the entered number by the user and displays the output on the screen
the program will display the result according to the user selection

 

Program 1

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num1,num2;
printf("Enter the first number: ");
scanf("%d",&num1);
printf("Enter the second number: ");
scanf("%d",&num2);

printf("\nAddition of %d + %d",num1,num2);
printf(" = %d",(num1+num2 ));
printf("\nSubstraction of %d - %d",num1,num2);
printf(" = %d",(num1-num2));
printf("\nMultiplication of %d X %d",num1,num2);
printf(" = %d",(num1*num2 ));
printf("\nDivision of  %d / %d",num1,num2);
printf(" = %d",(num1/num2 ));

getch();
return 0;
}

When the above code is executed, it produces the following results

Enter the first number: 60
Enter the second number: 15

Addition of 60 + 15 = 75
Substraction of 60 - 15= 45
Multiplication of 60 X 15 = 900
Division of 60 / 15 =4

 

Program 2

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char ch;
    int num1,num2;
printf("Enter the first number: ");
scanf("%d",&num1);
printf("Enter the second number: ");
scanf("%d",&num2);
printf("Enter the operator you want(+, -, x, /) :");
scanf("%s",&ch);
if(ch=='+'){
    printf("Addition is %d",num1+num2);
}
else if(ch=='-'){
    printf("Subtraction is %d",num1-num2);
}

else if(ch=='+'){
    printf("Multiplication is %d",num1*num2);
}

else if(ch=='+'){
    printf("Division is %d",num1/num2);
}

else{
    printf("This operator not in use");
}

getch();
return 0;
}

When the above code is executed, it produces the following results

Case 1

Enter the first number: 60
Enter the second number:15
Enter the operator uoy want(+, -, *,/):+
Addition is 75

Case 2

Enter the first number: 50
Enter the second number:10
Enter the operator uoy want(+, -, *,/):+
Subtraction is 40

Case 3

Enter the first number: 100
Enter the second number:10
Enter the operator uoy want(+, -, *,/):*
Moltiplication is 1000

 

Case 4

Enter the first number: 60
Enter the second number:15
Enter the operator uoy want(+, -, *,/):/
Division is 4

Case 5

Enter the first number: 60
Enter the second number:15
Enter the operator uoy want(+, -, *,/):x
operator not in use

Related program in other languages

Java Add Subtract Multiply Divide

Cpp Add Subtract Multiply Divide

Python program to Add Subtract Multiply Divide

Sum of two numbers in Java

5 method to sum of two numbers

JavaScript program to sum of two numbers 

Addition of two numbers in Java using method

Addition of two numbers in PHP using Function

 

 

Suggested for you

An operator in C language

If statements in C language

Data type in C language

Cpp program to Addition Subtraction,Multiplication and division
Java code to Addition Subtraction,Multiplication and division
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

View Comments

Recent Posts

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago