Sum of Two Numbers in C Language

 Sum of Two Numbers in C

Introduction:

Adding two numbers is a fundamental operation in programming. This program demonstrates how to take user input and perform addition.

Program:

#include <stdio.h> int main() { int num1, num2, sum; printf("Enter two integers: "); scanf("%d %d", &num1, &num2); sum = num1 + num2; printf("Sum: %d", sum); return 0; }

Explanation:

  • int num1, num2, sum; : declared num1,num2 and sum as integer.
  • scanf("%d %d", &num1, &num2);: Reads two integers from the user and stores in num1 and num2 integers.

  • sum = num1 + num2;: Calculates the sum of the two numbers.

  • printf("Sum: %d", sum);: Used to displays the result in output screen.


Comments

Popular posts from this blog

C Program To Find Largest Number Among Three Integers

C Program To Convert Fahrenheit To Celsius

C Program To Reverse a Number