3/10/21

C Program to Add Two Integer Number -- C Programs

In our previous tutorial, we had made a simple program of C language in which we had printed Hello World on the display. Hope you guyz understood that program. Now, today I am going to make another C program which takes the 2 input from the user in the numerical value and gives us the sum of these two numerical value.  So Let’s Begin…

C Program to Add Two Numerical Value. 

#include<stdio.h>

int main()

{

int A,B,C;

printf("Enter the value of A=");

scanf("%d",&a);

printf("Enter the value of B=");

scanf("%d",&b);

c=a+b;

printf("Answer is=%d",c);

getch();

}

Output :- 


Look at the function used in the above code

1. In the first line of code we include a header file named <stdio.h> which is used to add the printf, scanf function in the program. 

2. On the second line of the code we use int main () function. It shows that your program starts executing from here. 

3. After that we declare 3 variable (A, B, C) respectively. The first variable A store the first numerical value and the second variable B store the second numerical value and the sum of these two number are stored on the third variable C. 

4. After the declaration of the variable we give the message to the user to enter the first number. We use printf() function to give the message which is printed on the monitor screen.

5. After the message the value provided by the user was stored in the first variable name A. we assign the value into A variable by using scanf() function. 

6. In scanf() function we use %d on it. %d indicates the compiler that the user gives an integer value to it.

7. You also notice that we use & (and) symbol on both scanf function what are their mean. The & symbol tell the compiler that the input given by the user is stored on the specific location. (The first value stored on A variable and the second value stored on B variable respectively).

8. At the last line of code we use a function name getch(). This function is used to hold the output screen until the user presses any button or click on the output screen. 


0 comments:

Post a Comment

Like us on facebook

blogger templatesblogger widgets

Follow on Twitter

Linkedin

Categories

Mad About Computer. Powered by Blogger.