How to add 2 numbers in C programming language?

Simple C Program to Add Two Numbers:


 Description:

  1. The program begins by including the necessary header file stdio.h, which provides input/output functions like printf() and scanf().

  2. The main() function is the entry point of the program.

  3. Inside the main() function, we declare three integer variables: num1, num2, and sum. These variables will store the two numbers to be added and their sum, respectively.

  4. The program prompts the user to enter the first number using the printf() function.

  5. The scanf() function is used to read the user's input and store it in the num1 variable.

  6. Similarly, the program prompts the user to enter the second number and reads it using scanf(), storing it in the num2 variable.

  7. The sum variable is assigned the value obtained by adding num1 and num2.

  8. Finally, the program uses printf() to display the result, showing the original numbers entered by the user and their sum.

  9. The return 0; statement signifies the end of the program execution.

To run this program, save it with a .c extension (e.g., add_numbers.c), compile it using a C compiler, and execute the resulting binary file. Then you can input two numbers, and the program will calculate and display their sum.

Refer the video for better understanding:

Post a Comment

Go to my YouTube channel👉 Kailash Namata Subscribe the channel🔔