Add Two Numbers In C

In this blog post, we will checkout the how to add two numbers in C.

Algorithm to Add Two Numbers in C

To create a C program to add two numbers, you can follow this algorithm.


  1. Start: Begin the process.
  2. Input two numbers: Prompt the user to input the two numbers.
  3. Add both the numbers: Use the formula num1 + num2 to calculate the addition.
  4. Display answer: Show the calculated answer to the user.
  5. End: Conclude the process.

Program to Add Two Numbers in C

#include <stdio.h>

int main() {
    int number1, number2, result;

    // Prompting user for the two numbers
    printf("Enter first number: ");
    scanf("%d", &number1);
    printf("Enter second number: ");
    scanf("%d", &number2);

    result = number1 + number2;

    // Displaying the result
    printf("The sum of %d and %d is: %d\n", number1, number2, result);

    return 0;


image 3


  • Step 1: The program starts by including the standard input-output library stdio.h for basic input/output operations.
  • Step 2: In the main function, three integer variables are declared: number1, number2, and result.
  • Step 3: The program then prompts the user to enter the first and second numbers, which are read and stored in number1 and number2 respectively using scanf.
  • Step 4: The sum is calculated.
  • Step 5: Finally, the program prints the result using printf.

Time Complexity: The time complexity of this program is O(1).

Space Complexity: The space complexity of the program is also O(1).

If you liked this post you can checkout other C Programs.

90% of Tech Recruiters Judge This In Seconds! 👩‍💻🔍

Don’t let your resume be the weak link. Discover how to make a strong first impression with our free technical resume review!

Related Articles

Subtraction of Two Numbers Program in C

In this blog post, we will checkout the Subtraction of Two Numbers Program in C. How to Write Subtraction Program in C? To create a C program to subtract two

Why Aren’t You Getting Interview Calls? 📞❌

It might just be your resume. Let us pinpoint the problem for free and supercharge your job search. 


Don’t miss out! Subscribe now

Log In