Addition of two numbers in C Programming

Addition of two numbers in C Programming is basic and simple task.

We can create it very easily.

Writing a program is based on Algorithm.

An algorithm is step by step description of program.

So before writing program we must write algorithm to develop this program.

There are different ways to represent an algorithm

1 Flow chart
2. Pseudocode

Flow chart to add two numbers

Flowchart To Add Two Numbers
Flowchart To Add Two Numbers

pseudo code for adding two numbers

  1. Start Program
  2. Input two numbers a and b
  3. sum=a+b
  4. Print sum
  5. End Program

Example Addition of two numbers in C

here %d is used to print integer value we can also use %i.

Result

Addition program in C with user Input

Fig: Data Type Promotion in addition

Here one variable is int type another is float type.

So int value is automatic promoted to float value

now both are float and its result is float.

This automatic promotion is known as widening.

Output

Addition program in C of Two long numbers

C Program to add two float numbers

C Program to add two double numbers

Addition of two numbers in C using command line arguments

gcc add.c

./a.out 6 4

Addition of two numbers in C using command line arguments
Fig: Addition of two numbers in C using command line arguments

Here function atoi() is used to convert string to integer value

Addition of two numbers in C using function

We discussed addition of two numbers in C Programming.

Read More

Break And Continue Statement In C With Example

Array Of Pointers In C Programming