nested_loop_aloba
nested_loop_aloba
Instructions
1. Do not change the format of the template.
2. Submit your document as “nested_loop_lastname.pdf”.
3. Put answers on items in RED.
Activity
Create a program that will ask the user to input a number and displays a number of
triangles, square of ‘*’, and a diamond of ‘*’.
Note: Your display does not need to be in a table as long as it displays the three shapes
based on user input.
Example 1:
Input a number: 3
Example 2:
Input a number: 5
Technological Institute of the Philippines – Manila
CITE 002 – Computer Programming 1
Number of triangle Square of ‘*’ Diamond of ‘*’
1 ***** *
12 ***** ***
123 ***** *****
1234 ***** *******
12345 ***** *********
Evidences/Answer
1. Run the program and input a random number between 5 – 10. Take a screenshot
and put it below.
Technological Institute of the Philippines – Manila
CITE 002 – Computer Programming 1
2. Run the program and input a random number between 5 – 10. Take a screenshot
and put it below.
Technological Institute of the Philippines – Manila
CITE 002 – Computer Programming 1
3. Source code. Put your raw source code below. Not a screenshot.
#include <iostream>
using namespace std;
int main()
{
cout << "Input a number: ";
int num; cin >> num;
//number triangle
cout << endl << "Number of triangle" << endl;
for (int i = 1; i <= num; i++){
for (int j = 1; j <= i; j++) cout << j;
cout << endl;
}
return 0;
}