How to add two numbers in C programming language
- Get link
- X
- Other Apps
How to add two numbers in the C programming language
In this blog post, we will look at how we can use Visual Studio Community 2022 and write C language code to add two numbers.
1) Writing the program:
This is a very basic and most important program for beginners. In this program, beginners deal with input and output functions like print() and scanf() for input and output.
Let's dive into the coding part:
2) Explaining the coding part:
At the start of the code, we can look at two lines starting with #define and #include. The first line is written so we can use print() and scanf() without any safety warning because printf_s() and scanf_s() are now preferred because they are safer to use. In the second line, we use stdio.h header file so that we can use input and output functions i.e., print() and scanf().
The int main() function is the entry point to your C program. It is a necessary function to run your C code. After that, we declared three variables num1, num2, and sum. We are going to take user input in these variables and then manipulate data according to our requirements.
In the next lines we used print() and scanf() functions to print messages for entering numbers using printf() and store values in variables num1, num2, using scanf() function.
After that, we are going to add integer variables num1 and num2 using the + operator and store their result in the sum variable.
Congratulations to everyone we have successfully added two numbers using the C program.
- Get link
- X
- Other Apps
Comments
Post a Comment