Complementary task for topic: 1

M Nemeth · 2023-08-29 15:21:04.599220'

Printf: integer addition

Printf: integer addition

Write a C program that performs a an addition using predefined integer variables and uses printf() to display the result.

Hint: Use %d for decimal print

Solution
#include 

int main() {
    int operand1 = 10;
    int operand2 = 5;
    
    int result = operand1 + operand2;
    
    printf("The result is %d.\n", result);
    
    return 0;
}


Explanation
In this example, we have two predefined integer variables operand1 and operand2 set to 10 and 5, respectively. The program performs the addition operation between the two operands and stores the result in the result variable. Then, it uses printf() to display the result with the specified format.

When you run the program, it will output the result of the mathematical operation using printf() as specified in the task. The %d format specifier is used to print integer values.
next > >