We read your photo as:

Write a C program to add two numbers and display the result.

Computer Science

ScanSolve AI Answer

Here is a C program to add two numbers and display the result.

#include <stdio.h> // Required for input/output functions like printf

int main() {
    // Declare integer variables to store the two numbers and their sum
    int number1 = 10;
    int number2 = 25;
    int sum;

    // Calculate the sum of the two numbers
    sum = number1 + number2;

    // Display the numbers and their sum on the computer screen
    printf("First number: %d\n", number1);
    printf("Second number: %d\n", number2);
    printf("Sum of the two numbers: %d\n", sum);

    return 0; // Indicate successful program execution
}

Explanation:

  • The #include <stdio.h> line includes the standard input/output library, which provides functions like printf for displaying output.
  • The main function is the entry point of every C program.
  • int number1 = 10; and int number2 = 25; declare two integer variables and initialize them with values.
  • int sum; declares an integer variable to store the result.
  • sum = number1 + number2; performs the addition.
  • printf() statements are used to display the values of number1, number2, and sum on the console. The %d is a format specifier for integers, and \n creates a new line.
  • return 0; indicates that the program executed successfully.

Output of the program:

First number: 10
Second number: 25
Sum of the two numbers: 35
Was this helpful?

Still stuck on this one?

Ask a follow-up, and the answer starts from this question.

Got a different question?Ask your own question