C PROGRAMMING NOTES ,IOE
5.2. Sequential Statement
In C programming, a sequential statement is a type of statement that is executed in a sequential or linear order. This means that each statement is executed one after the other, in the order in which they appear in the code. Most statements in C are sequential statements, as the default behavior of the language is to execute statements in the order in which they are written.
Here's an example demonstrating sequential statements in C:
#include <stdio.h>
int main() {
// Sequential statements
printf("This is the first statement.\n"); // Statement 1
printf("This is the second statement.\n"); // Statement 2
printf("This is the third statement.\n"); // Statement 3
return 0;
}
Output:
This is the first statement.
This is the second statement.
This is the third statement.
Here is another C program to add two numbers, that executes instruction sequentially:
#include <stdio.h>
int main() {
// Sequential statements to add two numbers
int num1, num2, sum;
// Input: Get the first number
printf("Enter the first number: ");
scanf("%d", &num1); // Statement 1
// Input: Get the second number
printf("Enter the second number: ");
scanf("%d", &num2); // Statement 2
// Processing: Add the numbers
sum = num1 + num2; // Statement 3
// Output: Display the result
printf("The sum of %d and %d is: %d\n", num1, num2, sum); // Statement 4
return 0; // Statement 5
}
Output:
Enter the first number: 10
Enter the second number: 20
The sum of 10 and 20 is: 30