C++ loops - 1 Repetition Session 2 2 Repetition Structures...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 Repetition Session 2 2 Repetition Structures Repetition Structures while while for for do while do while while ( logical expression) { Sequence ; } for (start value; exp; step) { Sequence; } do { Sequence; }while (logical expression) ; 3 #include <iostream> Using namespace std; void main() { int n , num, total=0,count= 0; cin>>n; while (count<n) { cin>>num; total+=num; count++; } cout << total; #include <iostream> Using namespace std; Void main() { int n , num, total=0; cin>>n; for ( int count=0; count<n; count++) { cin>>num; total+=num; } cout << total; #include <iostream> Using namespace std; void main() { int n , num, total=0,count= 0; cin>>n; do { cin>>num; total+=num; count++; } while ( count < n); cout << total; In the following example the three previously explained loops are used to calculate the sum of a set of n numbers. 4 Write a program to convert the numbers from decimal to binary....
View Full Document

This note was uploaded on 03/12/2012 for the course IT 101 taught by Professor Fadi during the Spring '12 term at University of Damascus.

Page1 / 17

C++ loops - 1 Repetition Session 2 2 Repetition Structures...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online