C Program to Add Two Numbers

CWC
2 Min Read
C Program to Add Two Numbers

C Programming is a programming language that is used for developing portable applications or firmware. It is among the most widely used programming languages and many further programming languages stemmed from C Programming, such as C++. C Programming is flexible since it can be used in a variety of different applications. C Programming is not easy. In fact, it takes time and commitment to learning. Fortunately, you don’t have to spend your entire life on it either. Here is an example of a c programming code example to add two numbers, specifically integers and the accompanying explanation on how to C Program to Add Two Numbers.

[/dm_code_snippet]

Output of program

In the function (c = a + b) overflow may be experienced if the result of adding a and b is larger than the maximum value which can be stored in variable c.

Addition necessary without using a third variable.


#include
Main ()
{
Int a = 1, b = 2;
/* storing result of addition in variable a */
a = a + b;
/** Not mostly accepted because original value of a is lost 
* And you may be applying it somewhere in code considering it 
* As it was inputed by the user. > 
*/
Printf ("Sum of a and b = %d\n", a);
Return 0;
}
Long result;
Result = a + b;
Return result;
}

We have applied long data type as it can deal with large numbers, if you want to add still integers that don’t fit in long-range then use an array, string, or other data structure programming is simple just start to practice today and you will see improved results.

Share This Article
Leave a comment

Leave a Reply

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

English
Exit mobile version