There are five fundamental arithmetic operators found in C language, which are addition(+), subtraction(-), multiplication(-), division(/) and modulus(%) of two numbers. All arithmetic operators usually compute the result of particular arithmetic operation and returns its result.
This program performs essential paired number juggling operation on two whole number operands like expansion, subtraction, division and modulus and prints result in screen. It first takes two whole numbers as contribution from client utilizing scanf capacity and stores them in “firstNumber” and “secondNumber” int factors and performs expansion, subtraction, increase, division and modulus operations and stores brings about ‘entirety’, “difference” , ‘item’, “remainder” and “modulo” factors individually. Next, it prints the outcome on screen utilizing printf work.Here ia a program on How to perform addition, subtraction, multiplication and division in C program.
/*
* C Program for Addition, Subtraction, Multiplication, Division
* and Modulus of two numbers
*/
#include
#include
int main(){
/* Variable declation */
int firstNumber, secondNumber;
int sum, difference, product, modulo;
float quotient;
/* Taking input from user and storing it in firstNumber and secondNumber */
printf("Enter First Number: ");
scanf("%d", &firstNumber);
printf("Enter Second Number: ");
scanf("%d", &secondNumber);
/* Adding two numbers */
sum = firstNumber + secondNumber;
/* Subtracting two numbers */
difference = firstNumber - secondNumber;
/* Multiplying two numbers*/
product = firstNumber * secondNumber;
/* Dividing two numbers by typecasting one operand to float*/
quotient = (float)firstNumber / secondNumber;
/* returns remainder of after an integer division */
modulo = firstNumber % secondNumber;
printf("\nSum = %d", sum);
printf("\nDifference = %d", difference);
printf("\nMultiplication = %d", product);
printf("\nDivision = %.3f", quotient);
printf("\nRemainder = %d", modulo);
getch();
return 0;
}
Program Output
Enter First Number: 25 Enter Second Number: 4 Sum = 29 Difference = 21 Multiplication = 100 Division = 6.250 Remainder = 1
Relational Operator
These operators are utilized as a part of making a correlation between two amounts or take certain choices. For example, a social administrator thinks about the age of two individuals or the cost of two things.
a
is called social expression and the esteem is it is possible that one or zero or genuine or false, separately.
Logical Operators
This logical apparatus can be used in a program to test if the condition is true or force. Logical operators are utilized to assess complex standard expressions and are utilized as a part of mixes with social administrators to test at least one conditions and decide. C has three logical Operators: &&:
It is logical AND operator. When both operands are not-zero, then the condition becomes true ||:
It is called OR logical operator. If one of the two operands is not-zero, then the condition usually becomes true.!: It is Logical NOT and is utilized to change the logical state of the operand. If the condition is 1 the NOT operator can make it false and vice versa.