C++ Program to Print Numbers from 1 to 5 using Loops - Prof. David Jacobs, Study notes of Computer Science

The code for a c++ program that prints numbers from 1 to 5 using different types of loops: a for loop, a while loop, and two nested for loops. The program demonstrates how to control the flow of execution using loop structures.

Typology: Study notes

2010/2011

Uploaded on 10/19/2011

jayj8892
jayj8892 🇺🇸

2 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
For (int I = ; I <= 5; I = I + 1) {
Sopl(i); (prints 1,2,3,4,5)
While (i<=5){
Sopl(i);
I = I + 1;
For (int I = 1; I <= 5; I = I + 1){
For (int j = 1; j <= i; j = j + 1){
Sop(j);
}sop(‘\n’);
1
12
123
1234
12345
For( int I = 5; I >= 5; I = I - 1){
For(int j = 1; j <= i; j = j + 1){
Sop(j);
}sop(‘\n’);
12345
1234
123
12
1

Partial preview of the text

Download C++ Program to Print Numbers from 1 to 5 using Loops - Prof. David Jacobs and more Study notes Computer Science in PDF only on Docsity!

For (int I = ; I <= 5; I = I + 1) { Sopl(i); (prints 1,2,3,4,5) While (i<=5){ Sopl(i); I = I + 1; For (int I = 1; I <= 5; I = I + 1){ For (int j = 1; j <= i; j = j + 1){ Sop(j); }sop(‘\n’); 1 12 123 1234 12345 For( int I = 5; I >= 5; I = I - 1){ For(int j = 1; j <= i; j = j + 1){ Sop(j); }sop(‘\n’); 12345 1234 123 12 1