Arithmetic Expressions :
An arithmetic expression is a combination of variables, constants, and arithmetic
operators that evaluates to a numeric value. Arithmetic expressions are used in
assignment statements, decision-making statements, and loop conditions to perform
calculations within a program.
C supports the arithmetic operators addition (+), subtraction (-),
multiplication (*), division (/), and modulus (%). The evaluation of an
arithmetic expression follows specific operator precedence rules, which
determine the order in which operations are performed. Operators with higher
precedence are evaluated before those with lower precedence, and parentheses may
be used to override the default precedence.
Correct use of arithmetic expressions is essential for accurate computation and
logical correctness of a program.
An arithmetic expression is a combination of variables, constants, and arithmetic
operators that evaluates to a numeric value. Arithmetic expressions are used in
assignment statements, decision-making statements, and loop conditions to perform
calculations within a program.
C supports the arithmetic operators addition (+), subtraction (-),
multiplication (*), division (/), and modulus (%). The evaluation of an
arithmetic expression follows specific operator precedence rules, which
determine the order in which operations are performed. Operators with higher
precedence are evaluated before those with lower precedence, and parentheses may
be used to override the default precedence.
Correct use of arithmetic expressions is essential for accurate computation and
logical correctness of a program.
SYNTAX:
sum = number1 + number2;
EXAMPLE:
// Sum without user input
#include <stdio.h>
int main() {
int a = 1;
int b = 2;
int sum = a+b;
printf("%d",sum);
return 0;
}
Output :
3
EXAMPLE:
//Sum with user input
#include <stdio.h>
int main()
{
int number1, number2, sum;
printf("Enter two numbers: ");
scanf("%d %d", &number1, &number2);
sum = number1 + number2;
printf("Sum = %d", sum);
return 0;
}
Output:
Enter two numbers: 10
10
Sum = 20