Gillius's Programming Forums

Hosted Forum: West Visayas State University - Philippines => Problem Solving and Programming Class Forum => Topic started by: louiecerv on December 07, 2005, 01:14:06 AM

Title: Triangle of Numbers
Post by: louiecerv on December 07, 2005, 01:14:06 AM
Code: [Select]

#include <iostream>
using namespace std;

int main()
{
    int lines;
    cout << "NUMBER TRIANGLE" << endl <<endl;
    cout << "A program to display a triangle of numbers.\n";
    cout << "Number of lines to show: ";
    cin >> lines;
   
    int num = 1;
    for (int count = 0; count < lines; count++)
    {
        for (int row = 0; row <=count; row++)
        {
            cout << num;
            num++;
            if (num>9) num = 1;
        }
        cout << endl;
    }
   
    system("PAUSE");
    return 0;
}


Highlight:  Use of the nested for loop