C PROGRAMMING

Add three numbers using c programming

Adding three numbers using C Program

#include <stdio.h>
#include <conio.h>
void main()
{
int n1,n2,n3,sum;
printf("Enter first numbern");
scanf("%d",&n1);
printf("Enter second number to add n");
scanf("%d",&n2);
printf("Enter third number to see sum of entered numbersn");
scanf("%d",&n3);
sum=n1+n2+n3;
printf("Sum of entered numbers is %d ",sum);
getche();
}

Explanation of some important points

1. #include <stdio.h> and #include <conio.h>  these are known as header files. These should be included in program to use pre-defined library functions.

2. int n1,n2,n3,sum;  This statement is used to declare 4 variables.

3. printf(“some text”); This statement is used to display text message on screen.

4. scanf(“%d”,&n1); This statement is used to get numbers form keyboard and stored in variables like n1 which of type integer.

5. sum = n1+n2+n3; This command is used for calculation purpose. Here sum is assigned the added values of n1, n2,n3.

6. getche(); This statement is used essentially to get  a character form keyboard. But in our program we used it to hold the screen and when we hit a key on keyboard the screen changes to code.

Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button