GET EDUCATE

Contents
Basics of C Programming

⯈Basic C Programs

Algorithm and Flowchart to add two numbers

Whenever we write an algorithm or program, “always read the input first”. The input to this algorithm is any two numbers. So let us assume that A and B be some numbers. To read the input from the end user, we use “Read“, some use “Input“, that is perfectly ok to use anyone. 

So, two read the input we may write,

Read two numbers as A and B. you could even write as Read A and B. The former is more appealing as it says A and B are numbers, so let us stick to that.

After we read two numbers, the task is to add the two numbers, so let’s add, A + B. The value of A + B should be stored in some variable. A variable is like a container that holds some value. (More about variables we will discuss in the Basics of C Programming chapter.) Hence, we store the answer in a variable. Let the variable name be Sum.

Therefore, we write, 

Sum = A + B, read as Sum is assigned with the value of A + B.

At the end the algorithm should have at least one output. Therefore we display the answer and that answer is stored in variable Sum. To output we use word “Display“, some use the word “Print

We write, Display Sum.

Note: An algorithm should be generic, it shouldn’t be specific. We shouldn’t write as , “Read two numbers 3 and 4”

Algorithm:

Name of Algorithm: To add two numbers.

Step 1: Start

Step 2: Read two numbers as A and B

Step 3: Sum = A + B

Step 4: Display Sum

Step 5: Stop

Flowchart:

flowchart sum two numbers

Tracing:

Let us do the dry run of the above algorithm:

At step number 2, it reads two numbers as A and B.

Let A = 10 and B = 20.

Step 3 computes, Sum = A + B, Sum = 10 + 20, Sum = 30

At Step 4: Display the value stored in Sum, i.e., 30 and we stop the algorithm.

 

Scroll to Top