C Program to Add two numbers

Here’s a simple program in C language to add two numbers entered by the user:

#include <stdio.h>

int main() {
    int num1, num2, sum;

    printf("Enter the first number: ");
    scanf("%d", &num1);

    printf("Enter the second number: ");
    scanf("%d", &num2);

    sum = num1 + num2;

    printf("The sum of %d and %d is %d", num1, num2, sum);

    return 0;
}

In this program, we first declare three integer variables num1, num2, and sum, where num1 and num2 are the two numbers entered by the user, and sum is the variable that will hold the sum of these two numbers.

We then prompt the user to enter the first number using the printf() function and read the input using the scanf() function. Similarly, we prompt the user to enter the second number and read the input using the scanf() function.

Next, we add the values of num1 and num2 and store the result in the sum variable.

Finally, we use the printf() function to display the sum of the two numbers entered by the user.

When you run this program and enter two numbers, the output will be:

Enter the first number: 4
Enter the second number: 5
The sum of 4 and 5 is 9

This program is a basic example of how to perform arithmetic operations in C language.

Posted in: C