Simple C Program to Add Two Numbers:
Description:
The program begins by including the necessary header file
stdio.h, which provides input/output functions likeprintf()andscanf().The
main()function is the entry point of the program.Inside the
main()function, we declare three integer variables:num1,num2, andsum. These variables will store the two numbers to be added and their sum, respectively.The program prompts the user to enter the first number using the
printf()function.The
scanf()function is used to read the user's input and store it in thenum1variable.Similarly, the program prompts the user to enter the second number and reads it using
scanf(), storing it in thenum2variable.The
sumvariable is assigned the value obtained by addingnum1andnum2.Finally, the program uses
printf()to display the result, showing the original numbers entered by the user and their sum.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