REPETITIVE STRUCTURES(LOOPS)INPUT/OUTPUT

AlonTashobya 8 views 15 slides Oct 19, 2025
Slide 1
Slide 1 of 15
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15

About This Presentation

The use of REPETITIVE STRUCTURES (LOOPS)
INPUT/OUTPUT in programming


Slide Content

LECTURE 4: REPETITIVE STRUCTURES (LOOPS) INPUT/OUTPUT

Repetitive Structures for …. statement while …. statement do….while statement

f or…statement Syntax: for (initial; condition; increment/decrement) { statement(s); }

Example 1: #include< stdio.h > int main() { int counter; for(counter=1;counter<=10;counter++) printf("%d\n", counter); return 0; }

while…statement Syntax: while (condition) { statement (s); }

Example 2: #include< stdio.h > int main() { int counter =1; while (counter<=150) { printf("%d\n", counter); counter++; } return 0; }

do…while Syntax: do { statement(s); } while(condition);

Example 3 # #include< stdio.h > int main() { int counter=1; do { printf ("%d\n", counter); counter++; } while (counter<=10); return 0; }

Fundamental Input/output The printf(): Used for displaying Information on the Screen Examples: printf("An error has occurred!"); printf("\n The value of x is %d", x); Output: The value of x is 12

Most Frequently Used Escape Sequences Sequence Meaning \a Bell (alert) \b Backspace \n Newline \t Horizontal tab \\ Backslash \? Question mark \' Single quotation

Using Printf() Escape Sequences Sequence Meaning N The character n \n Newline \" The double quotation character " The start or end of a string

Using Printf() Conversion Specifiers Specifier Meaning Types Converted %c Single character Char %d Signed decimal integer int, short %ld Signed long decimal integer Long %f Decimal floating-point number float, double %s Character string char arrays %u Unsigned decimal integer unsigned int, unsigned short %lu Unsigned long decimal integer unsigned long

Puts() function puts("Hello, world."); Performs the same function as, printf("Hello, world.\n");

Inputting Numeric Data Scan () Function scanf("%d", &x); scanf("%f", &rate); scanf("%d %f", &x, &rate);

Read About! Flow Control , Repetitive Structures & Input/Output functions*. User Defined* & Pre-defined* Functions in C Study Carefully, Run all programs contained in the notes in the compiler of your choice to understand.
Tags