0% found this document useful (0 votes)
11 views10 pages

Structured Program Development Presentation

The document discusses structured programming in C, emphasizing the use of clear control structures like if, if...else, and while loops to enhance readability and reduce complexity. It provides explanations and example programs for each control structure, including nested statements. The examples illustrate how to implement these structures in C programming effectively.

Uploaded by

Rida Zaniab
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views10 pages

Structured Program Development Presentation

The document discusses structured programming in C, emphasizing the use of clear control structures like if, if...else, and while loops to enhance readability and reduce complexity. It provides explanations and example programs for each control structure, including nested statements. The examples illustrate how to implement these structures in C programming effectively.

Uploaded by

Rida Zaniab
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Structured Program Development

in C

– Structured programming uses clear control


structures.
– Reduces complexity and increases readability.
– Main structures: if, if…else, while, nested
statements.
IF Statement – Explanation

– Used to execute a block of code only when a


condition is TRUE.
– Syntax: if (condition) { statements; }
– Condition must return true (non-zero) or false (0).
IF Statement – Example Program

– #include <stdio.h>
– int main() {
– int age = 18;
– if(age >= 18) {
– printf("You are eligible to vote.\n");
– }
– return 0;
–}
IF…ELSE Statement – Explanation

– Executes one block if condition is TRUE and


another if FALSE.
– Useful for two-way decisions.
IF…ELSE – Example Program

– #include <stdio.h>
– int main() {
– int num = 7;
– if(num % 2 == 0) {
– printf("Even number\n");
– } else {
– printf("Odd number\n");
– }
– return 0;
–}
WHILE Loop – Explanation

– Repeats a block of code as long as the condition is


TRUE.
– Check happens BEFORE loop body executes.
– Used when number of iterations is unknown.
WHILE Loop – Example Program

– #include <stdio.h>
– int main() {
– int i = 1;
– while(i <= 5) {
– printf("%d ", i);
– i++;
– }
– return 0;
–}
Nested Control Statements –
Explanation

– Using one control statement inside another.


– Allows building complex logic (nested if, nested
loops).
Nested IF Example Program

– #include <stdio.h>
– int main() {
– int a = 10, b = 20;
– if(a > 5) {
– if(b > 15) {
– printf("Both conditions are true\n");
– }
– }
– return 0;
Nested WHILE Example Program
– #include <stdio.h>
– int main() {
– int i = 1;
– while(i <= 3) {
– int j = 1;
– while(j <= 3) {
– printf("%d,%d ", i, j);
– j++;
– }
– i++;
– printf("\n");
– }
– return 0;
– }

You might also like