{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

C++ loops

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

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

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

View Full Document

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

View Full Document
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

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online