computing for engineering , data porgraming

yazaj12 10 views 13 slides Oct 15, 2024
Slide 1
Slide 1 of 13
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

About This Presentation

First program in C++ is to prints “Hello World!” message on the screen of the
computer. During the processing phase, we don’t need any parameter (variables)
for this problem.


Slide Content

COMPUTING FOR ENGINEERING
MS :HNADI ALI

Control Statements

Example : Write Program in C++ that Display Numbers
from 1 to 5 ?

#include <iostream>
using namespace std;
int main() {
int counter = 1;
while (counter <= 5)
{
cout<< counter ;
++ counter;
}
}

The do-while Loop
1- loop counter is any numeric variable ( int , float ,….).
2- The initial value of the loop counter is up to you, but you have to increment it to avoid
endless loops.
3- The Loop Body is Executed at least one Time.

The do-while Loop

The do-while Loop
The body of the loop is executed at first. Then the condition is evaluated.
If the condition evaluates to true, the body of the loop inside the do statement is
executed again.
The condition is evaluated once at least.
This process continues until the condition evaluates to false. Then the loop stops.

The do-while Loop
The do...while loop is a variant of the while loop with one important difference:
the body of do...while loop is executed once before the condition is checked.

The do-while Loop
Example : Write a program that calculates and prints out the Average
grade for 6 students .

The do-while Loop
int counter = 1;
int grade=0 , sum=0;
do
{
cout<<"Enter grade for student no " << counter <<"\n"
cin>>grade;
sum = Sum + grade;
counter ++;
}
while (counter >=6) ;
cout<<"Average Grade is " << sum/6 <<"\n";

The do-while Loop
Example : Write Program in C++ that Display Numbers
from 1 to 5 ?

The do-while Loop
Example : Write a C++ program that print phrase hello
10 times?

The do-while Loop