Slider

C Program to Add Two Integer Number.

C Code to Add Two Integer values. To add two integer numbers we use the addition operator (+) and store the result in another integer variable.

Adding two integer numbers is one of the fundamental operations in any programming language, including C. To add two integer numbers we use the addition operator (+) and store the result in another integer variable. To learn this program you must basic understanding of input and output operators in C Programming.

Addition of Two Numbers

Step-by-step algorithm for Addition:

Step 1: Declare three variables, num1, num2, and sum.

Step 2: Take user input for values of num1 and num2 and store it in the variables.

Step 3: Add the value of num1 and num2 and store the result in the variable sum.

Step 4: Display the value of the sum as a result. 

Step 5: End the program.


C Code to Add Two Integer values.

//C Program to add two Integer number
#include <stdio.h>

int main() {
    // Step 1: Declare variables
    int num1, num2, sum;

    // Step 2: Input first number
    printf("Enter the first integer: ");
    scanf("%d", &num1);

    // Step 3: Input second number
    printf("Enter the second integer: ");
    scanf("%d", &num2);

    // Step 4: Perform the addition
    sum = num1 + num2;

    // Step 5: Display the result
    printf("The sum of %d and %d is %d.\n", num1, num2, sum);

    return 0;
}
Output:
Enter the first integer: 10
Enter the second integer: 5
The sum of 10 and 5 is 15.
  • Time Complexity: O(1)
  • Space Complexity: O(1)
0

No comments

Post a Comment

both, mystorymag

DON'T MISS

Tech News
© all rights reserved
made with by AlgoLesson
Table of Contents