0% found this document useful (0 votes)
10 views2 pages

Mini Final ppt-1

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)
10 views2 pages

Mini Final ppt-1

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
You are on page 1/ 2

Lab Manual: Programming for Problem Solving

Experiment 5: Write a Program in C to demonstrate the working of Loop Control Structures in C


1. Calculate the sum of 13 + 23 + 33 + 43 + 53 + …………..+ n3
2. Check whether the given number is Armstrong number or not
3. Factorial of a given number
4. Display prime number given within the range of numbers

Theory:
In programming, loops are used to repeat a block of code until a specified condition is met. C
programming has three types of loops.

 while loop
 for loop
 do-while loop

1. While Statement
Syntax:
while (testExpression )
{
//Statements to be executed repeatedly
// Increment (++) or Decrement (--) Operation
}
 The while loop evaluates the testExpression inside the parentheses ().
 If testExpression is true, statements inside the body of while loop are executed. Then,
testExpression is evaluated again.
 The process goes on until testExpression is evaluated to false.
 If testExpression is false, the loop terminates (ends).

2. do-while Statement

The do-while statement is used to execute a single statement or block of statements


repeatedly as long as given the condition is TRUE. The do-while statement is also known
as the Exit control looping statement.
Syntax:
do
{
statement;
}
while (expression); // don't forget the final;
In a do-while loop, if the value of expression is true (nonzero), the loop continues. The
loop will exit only when the value of expression becomes false (zero).
The do-while statement, tests at the bottom after making each pass through the loop
body; the body is always executed at least once.

3. For statement
The for loop operation is controlled by the contents of the parentheses that follow the
keyword for

Syntax: for (initializationStatement; testExpression; updateStatement)


{
// statements inside the body of loop

13
Lab Manual: Programming for Problem Solving

}
Working:
• The initialization statement is executed only once.
• Then, the test expression is evaluated. If the test expression is evaluated to false,
the for loop is terminated.
• However, if the test expression is evaluated to true, statements inside the body of
the for loop are executed, and the update expression is updated.
• Again the test expression is evaluated.
• This process goes on until the test expression is false. When the test expression is
false, the loop terminates.

Write All Programs with its output (Any 2 Programs):


i. Algorithm
ii. Flowchart
iii. Program
iv. Output.
Conclusion: In this practical, we have learned about of loop control statements in C Language by
implementing the while and for looping statements.

14

You might also like