# C program to add two numbers devquora

Posted On: Dec 23, 2020 ### Overview:

Before, Starting this article First of all, I want to introduce you to Mathematics, Arithmetic, Then I will explain What is a Number? and Definition of Addition. Furthermore, I will demonstrate and write logic for the addition process with an example. After all, I will show a C Program to add two numbers using 3 way i.e. (1) C program to add two integers in a simpler way with output. (2) C program to add two real numbers by using a function with output. (3) C program to add two numbers according to the user's choice with output. After that, I will explain the internal execution of the program.

### What is Mathematics?

Mathematics is a approach of calculation that uses numerals to perform any task.

### What is Arithmetic?

Arithmetic is the branch of mathematics dealing with the properties and manipulation of numbers. It has properties of operations such as addition, subtraction, Multiplication, division, modulus, increment and decrement, etc.

### What is a Number?

Number is an object that uses digits to perform mathematical tasks. Calculus, which is a branch of mathematics includes many numbers such as integers, whole numbers, real numbers, and imaginary numbers, etc. Here, I will discuss about number to perform arithmetic addition operation. Moreover, Number is a combination of digits, some symbols and decimal point. For instance, 127.23 is a decimal number.

Addition is the arithmetic operation which is the action or process of adding the first number to another. Addition is written using the plus sign "+" between the terms. For instance, If you want to add two integers such as 24 and 12 the summation of these two numbers is 36 i.e. 24+12=36.

• Step 1: Set up the numbers vertically
• Step 2: Star from the last right digits of numbers and add the digits in the ones place. Write the one's digit of it in the answer’s ones place and carry the other in the next tens place and add it with ten's digits.
• Step 3: Repeat Step 2 for all places until the first left digit of numbers. ### C program to add two integers in a simpler way with output.

```#include<stdio.h>
#include<conio.h>
void main()
{
scanf("%d",&num1);
scanf("%d",&num2);
}
```

The output of the Program: ### C program to add two real numbers by using a function with output.

```#include<stdio.h>
#include<conio.h>

int main()
{
int num1, num2, res;
printf("\n Enter First Number:\t");
scanf("%d", &num1);
printf("\n Enter Second Number:\t");
scanf("%d", &num2);
printf("\n Addition of Two Numbers: %d", res);
printf("\n");
return 0;
}

{
int sum;
sum = num1 + num2;
return sum;
}
```

The output of the Program: ### C program to add two numbers according to the user's choice with output.

```#include<stdio.h>
#include<conio.h>
int main()
{
char ch;

while (1) {
printf("Input First integer! ");
scanf("%lf", &num1);
printf("Input Second integer! ");
scanf("%lf", &num2);
getchar();

printf("(%lf) + (%lf) = (%lf)\n", num1, num2, add);

printf("Do you wish to add more numbers (y/n)\n");
scanf("%c", &ch);

if (ch == 'y' || ch == 'Y')
continue;
else
break;
}

return 0;
}
```

The output of the Program: Conclusion: Explanation of This Program with output. The internal working of this program depends upon the previous demonstration of addition of numbers.

This Program stores two integers into the int datatype by using to variables. After that store the sum of these two variables into another variable and display it on the screen.

After the successful compilation of the program, Program sums up the two entered numbers at once.