Home » C Programs » C Program For Sum of Digits

C Program For Sum of Digits

The user is requested to enter two integers in this example. The sum of these two integers is then computed and shown on the screen. You should be familiar with the following c programming subjects, such as basic c programs, in order to comprehend this example.

Addition Operator in C

In this application, Printf() displays the text Hello World on the screen. The user is requested to enter two integers in this software. Variables a and b are used to store these two integers. 

Then, using the + operator, these two values are added, and the result is saved in the sum variable. This program can be called as c program for sum of digits.

Operator in C

A symbol that directs the compiler to execute particular mathematical or logical operations is known as an operator. The C programming language has a large number of built-in operators, including the following: 

Arithmetic Operators It contains addition, subtraction, multiplication, division, modulus operations, increment, and decrement, as well as other fundamental arithmetic operations.

Mathematical computations are carried out using arithmetic operators. The assignment operators are used to give a property or variable a value. Numeric, date, system, time, and text can all be used as assignment operators. To accomplish comparisons, comparison operators are employed.

C Program For Sum of Digits

//c program for sum of digits
#include <stdio.h>
int main()
{ 
int a, b, sum;
printf("Enter two integers");
scanf("%d %d", &a, &b);
sum = a + b; 
printf("%d + %d = %d", a, b, sum);
return 0;
}

Output:

Enter two integers 45
45
45 + 45 = 90