c
  1. c-program-to-add-two-integers

Program to Add Two Integers - (C Programs)

Example:

In this program, we will take two integers as input and add them. The output will be displayed on the screen.

#include<stdio.h>

int main() {
   int firstNumber, secondNumber, sum;
   printf("Enter two integers: ");
   scanf("%d %d",&firstNumber, &secondNumber);

   sum = firstNumber + secondNumber;

   printf("Sum of %d and %d = %d", firstNumber, secondNumber, sum);
   return 0;
}

Output:

The output of the above program will be:

Enter two integers: 5 7
Sum of 5 and 7 = 12

Explanation:

In the above program, we have declared three variables - firstNumber, secondNumber,and sum. We have used the printf() and scanf() functions to take the input from the user and display the output on the screen. We have then added the two numbers using the + operator and assigned the result to the variable sum. Finally, we have used the printf() function again to display the result on the screen.

Use:

This program can be used to add any two integers and get their sum. It can be used in various applications where addition of two numbers is required.

Summary:

This program is a simple example of adding two integers using the C language. It shows how to take input from the user, perform arithmetic operations, and display the output on the screen. It is a fundamental program that is used in many applications.

Published on: