Code |
Output |
/***********************************************
4_65a.cpp
print a string of numbers
***********************************************/
#include <iostream>
#include <string>
using namespace std;
void main()
{
for (int number = 1; number <= 10; number++)
cout << number;
}
|
12345678910
|
/*******************************************************
4_65b.cpp
print a string of numbers
*******************************************************/
#include <iostream>
#include <string>
using namespace std;
void main()
{
const int start = 1;
cout << "Enter the last number" << endl;
int finish;
cin >> finish;
for (int number = start; number <= finish; number++)
cout << number << ' ';
}
|
Enter the last number
9
1 2 3 4 5 6 7 8 9
|
/***********************************************************
4_65c.cpp
print a string of numbers
***********************************************************/
#include <iostream>
#include <string>
using namespace std;
void main()
{
const int start = 1;
cout << "Enter the last number: " << endl;
int finish;
cin >> finish;
for (int row = start; row <= finish; row++)
{
cout << "row " << row << ": ";
for (int number = start; number <= finish; number++)
cout << number << ' ';
cout << endl;
}
}
|
Enter the last number: 9
row 1: 1 2 3 4 5 6 7 8 9
row 2: 1 2 3 4 5 6 7 8 9
row 3: 1 2 3 4 5 6 7 8 9
row 4: 1 2 3 4 5 6 7 8 9
row 5: 1 2 3 4 5 6 7 8 9
row 6: 1 2 3 4 5 6 7 8 9
row 7: 1 2 3 4 5 6 7 8 9
row 8: 1 2 3 4 5 6 7 8 9
row 9: 1 2 3 4 5 6 7 8 9
|
/**********************************************************
4_65d.cpp
print a string of numbers
**********************************************************/
#include <iostream>
#include <string>
using namespace std;
void main()
{
const int start = 1;
cout << "Enter the last number: ";
int finish;
cin >> finish;
for (int row = finish; row >= start; row--)
{
cout << "row " << row << ": ";
for (int number = start; number <= finish; number++)
cout << number << ' ';
cout << endl;
}
}
|
Enter the last number: 9
row 9: 1 2 3 4 5 6 7 8 9
row 8: 1 2 3 4 5 6 7 8 9
row 7: 1 2 3 4 5 6 7 8 9
row 6: 1 2 3 4 5 6 7 8 9
row 5: 1 2 3 4 5 6 7 8 9
row 4: 1 2 3 4 5 6 7 8 9
row 3: 1 2 3 4 5 6 7 8 9
row 2: 1 2 3 4 5 6 7 8 9
row 1: 1 2 3 4 5 6 7 8 9
|