C Program to add two integers


This content was proof-read by Grammarly. You can Try Grammary for FREE

Problem

Write a program in C to add two integers and display the result on the screen.

C Program to add two integers

#include <stdio.h>
int main()
{
    int input1, input2, result;
    // AC - read the first number
    printf("Enter first number : ");
    scanf("%d", &input1);
    
    printf("Enter second number : ");
    scanf("%d", &input2);

    result = input1 + input2;
     
    printf("%d + %d = %d", input1, input2, result);

    return 0;
}

Output

Enter first number : 1                                                                                                                                                           
Enter second number : 2                                                                                                                                                                 
1 + 2 = 3

%d bloggers like this: