09 - C Sequential Statements

This chapter is going to explain the nature of C programs. Usually, C programs are sequential in nature.

Generally, sequence of statements are written in order to accomplish a specific activity. So statements are executed in the order they are specified in the program. This way of executing statements sequentially is known as Sequential control statements.           

There is an advantage that is no separate control statements are needed in order to execute the statements one after the other. 

Disadvantage is that there is no way to change the sequence. The solution for this is branching. We are already aware of the branching and loop control structures but the reason for their existence is the sequential flow of execution which troubles when we have to work on lot of data and activities to follow. We have already studied all basic branching and loop control structures and sample [rpgrams are also explained. Sequential nature of C program is one of the basic reasons behind the birth of other programming languages like C++, Java, etc. Let us see an example of sequential program.

Example: / * Program to illustrate sequential flow of execution */

# include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>

void main()
{
  float farenhite, celsius;

  printf("Enter degree in farenhite\n");
  scanf("%f", &farenhite);

  celsius=(float)5/9*(farenhite-32);
  printf("result=%f\n", celsius);
  getch();
}

Explanation: Execution begins from the main. We enter a farenhite degree value. Control moves to the formula which will convert farenhite into celsius and then equivalent celsius value is output. 

Program looks similar to the following snapshot:

 Figure – Sample C Program with Sequential

                    Figure – Sample C Program with Sequential

  Figure – Sample C Program with Sequential flow compiled output

 

Figure – Output of Sample C Program with Sequential flow

We conclude the chapter with this. Next chapter is dedicated to functions. Thank you.

Like us on Facebook