C Language | Addition part 1

Wednesday, 5 December 2012

Wherever we went we always encounter math, either when you're at home, in school or even in the market. Most of time, basic mathematics is always useful like addition and subtraction. Before, adding or subtracting is used with beads or stones or whatever things that might represent the figure all of it can be useful. Then, new generation has come and calculators were born. Today, computers are used. So, I thought of making a program that can add numbers just like a calculator using C language.

The program is designed to add two (2) numbers/integers using the basic mathematics and C language commands. Check out the codes below.



     #include<stdio.h>
     #include<conio.h>
     
     int main()
    {
     int a,b,c;
     
     printf("Enter number: ");
     scanf("%d", &a);
     
     printf("\nEnter number: ");
     scanf("%d", &b);
    
     c = a + b;
    
     printf("\nThe sum is %d", c);
     getch();
     }

In this program, we simply follow the rules of mathematics in adding numbers. As shown above, c = a + b illustrates the addition equation. Variables a and b holds the numbers entered by the user. While, variable c holds the sum of the numbers. Please note that the variables declared are used with a data type int which means it only accepts whole numbers. Check out the sample output below.





Hope you learned something from this post. Thanks!



No comments:

Post a Comment

Please do leave a comment. It's gonna be a friendly conversation between programmers. Hope you do find our blog helpful. Thank you!

Related Posts Plugin for WordPress, Blogger...