Simple C Program for adding two numbers :
Sample Output:( using GNU GCC Compiler with Code Blocks IDE )
   Enter the first number to be added: 10
   Enter the second number to be added: 15
   The sum of two numbers is: 25
Explanation for the above program :1) The #include <stdio.h> includes the file stdio.h into your code so it knows what the functions such as  printf() mean.
2) main() is the main function in which you write most of your code. int is the default return type of main function.
3) int x; , int y; , and int result. the int stands for integer or a number (no decimal points you need a float for that) the X and Y are the numbers you are adding together and result is the result of the numbers.
4) printf(“nEnter the first number to be added: “);
scanf(“%d”,&x); the Printf() prints the text, Enter the first number to be added: onto the screen and the

     scanf(“%d”,&x); looks for the number input from the keyboard for x.

5) printf(“n Enter the second number to be added: “);

      scanf(“%d”,&y); do the same as the last 2 lines except it looks for value for y instead of x.
6) result = x + y; that adds the values of X and Y and stores the result in the variable result.
7) printf(” The sum of two numbers: %dn”,result);  that prints the result on the screen
   return(0); tells the OS that the program ended  successfully.

Leave a Reply

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