0% found this document useful (0 votes)
7 views

C Module 3 Sesstion 5

Uploaded by

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

C Module 3 Sesstion 5

Uploaded by

rupeshreddy2003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 54

Placement Training Programme June 2024

Dr. SHRUTHISHREE S.H B.E., M.Tech., Ph.D in CSE

Assistant Professor | Department of Computer Science & Engineering | Faculty of Engineering & Technology

JAIN (Deemed-to-be University)


Types of Control Statements in C

There are three main types of control statements in C

Selection Statements (Conditional Statements)

Iteration Statements (Loops)

Jump Statements

PLACEMENT TRAINING PROGRAMME :INTRODUCTION TO C PROGRAMING | 2024


SESSION 4:MODULE 3
CONTROL FLOW

Iteration Statements (Loops)

Jump Statements

PLACEMENT TRAINING PROGRAMME :INTRODUCTION TO C PROGRAMING | 2024


Table of Contents

Definition of Loops in C

Types of Loops
Nested Loops
Control Statements
Real-Case Examples
Importance
PLACEMENT TRAINING PROGRAMME :INTRODUCTION TO C PROGRAMING | 2024
#include <stdio.h>
int main() {
int distanceInMeters = 1000;

while (distanceInMeters > 0)


{
printf("Driver is %d meters away...\n", distanceInMeters);
distanceInMeters -= 200; // Assuming the driver covers 200
meters every iteration.
}
printf("Your Uber has arrived!\n");
return 0;
}
Output
Driver is 1000 meters away...
Driver is 800 meters away...
Driver is 600 meters away...
Driver is 400 meters away...
Driver is 200 meters away...

Your Uber has arrived!

The program uses a loop to simulate the approaching Uber/Ola driver by


decreasing the distance in increments of 200 meters. The loop exits when the
driver reaches your location, and the final message is displayed.
// C Program to print multiplication table using do-while
// loop
#include <stdio.h>
int main()
{ int N = 7, i = 1;
do
{
printf("%d\tx\t%d\t=\t%d\n", N, i, N * i);
}
while (i++ < 10);
return 0;
}
Output
7x1=7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
7 x 8 = 56

7 x 9 = 63 7 x 10 = 70

We printed the table of 7 here using the do-while loop in C.


PLACEMENT TRAINING PROGRAMME :INTRODUCTION TO C PROGRAMING | 2024
#include <stdio.h>

int main() {
for(int i = 1; i <= 7; i++) {
printf("%d\n", i);
}
return 0;
}
PLACEMENT TRAINING PROGRAMME :INTRODUCTION TO C PROGRAMING | 2024
3. Nested do-while Loops
Nested do-while loops are similar to nested while loops.

They are useful for tasks that require the repeated execution
of specific actions based on a condition.
PLACEMENT TRAINING PROGRAMME :INTRODUCTION TO C PROGRAMING | 2024
Output
Welcome to the Number Guessing Game!
Enter your guess: Congratulations!
You guessed the correct number.
Thank you for playing!

The code uses the break statement to terminate


the loop when the player guesses the correct number. The
game will continue prompting the player for guesses until
they guess the target number, making it a functional and
interactive number-guessing game.
#include <stdio.h>
int main() {
int i;

printf("Printing even numbers


between 1 and 50:\n");

for (i = 1; i <= 50; i++) {


if (i % 2 != 0) {
continue; // Skip odd numbers
}
printf("%d\n", i);
}
return 0;
}
#include <stdio.h>
int main()
{
int num = 0;

print_num:
if (num < 7) {
printf("%d ", num);
num++;
goto print_num; // Jump back to
the label and execute the code again
}

return 0;
}
THANK U

53
https://unstop.com/blog/control-statements-in-c

You might also like