Hey there! First-time visitor? Contact Us

Write a C program to take two numbers as input from the user and print their sum.

🔹 How It Works:

✅ Takes two numbers as input using scanf().
✅ Adds them using sum = num1 + num2;.
✅ Prints the result using printf().


 

#include 

int main() {
    int num1, num2, sum;
    
    // Taking input from the user
    printf("Enter first number: ");
    scanf("%d", &num1);
    
    printf("Enter second number: ");
    scanf("%d", &num2);
    
    // Calculating sum
    sum = num1 + num2;
    
    // Printing the result
    printf("Sum: %d\n", sum);
    
    return 0;
}

  
Output:
Enter first number: 5
Enter second number: 7
The sum of 5 and 7 is: 12

Post a Comment