English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

a)Use for loops how to construct a program that displays a pyramid of numbers on the screen.
The pyramid should look like this:
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Ask the user to enter a digit(0-9) and display the pyramid with limit up to that number( as shown above).
b)Draw a flowchart for the above program.
Hints
You may nest two inner loops, one to print spaces and one to print numbers (0-9), inside an outer loop that steps down the screen from line to line.
Sample Output
Enter a single digit (1 to 9): 5
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

2006-10-18 09:11:03 · 5 answers · asked by Anonymous in Computers & Internet Programming & Design

Make this code in C or C++

2006-10-18 10:29:55 · update #1

5 answers

this code is for C#

private static void Printing() {
for(int i = 1; i <= 5; i++) {

for(int j = 1; j <= i; j++)
Console.Write(i.ToString() + " ");

Console.WriteLine();
}
}

2006-10-18 10:00:40 · answer #1 · answered by Anonymous · 0 1

Just for fun I did it in VBA real quick :

Public Sub Pyramider()

Dim iResult As Variant
Dim iCounter As Integer
Dim sOutput As String
Dim i As Integer

iResult = InputBox("Enter a number :", "Number Pyramid", 9)
If IsNumeric(iResult) And iResult > 0 Then
Do
iCounter = iCounter + 1

sOutput = ""
For i = 1 To iCounter
sOutput = sOutput & CStr(iCounter)
Next i
Debug.Print sOutput

Loop Until iCounter = iResult
End If

End Sub

Enjoy! I hope you are not going to copy this and turn it in. Who knows... I might be your teacher. Mwuhahahah!

2006-10-18 10:02:25 · answer #2 · answered by Special Ed 5 · 0 0

you need at least two FOR loops, or maybe one FOR loop and one Do While. sorry can't help now im not in the mood to program. i'll just give u hints.

2006-10-18 09:18:18 · answer #3 · answered by a_very_curious_person 2 · 0 0

Wow I did the VERY same assignment for my intro to C++ class back in 2004! LOL, good times.

2006-10-18 09:52:24 · answer #4 · answered by D 4 · 1 0

try looking here:

2006-10-19 02:36:47 · answer #5 · answered by justme 7 · 0 0

fedest.com, questions and answers