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

The output should be as follows
2
2 3
2 3 5
2 3 5 7
2 3 5 7 11
2 3 5 7 11 13
The user inputs the number of rows he wants and that many rows of prime numbers as shown above should be printed.

2007-03-04 20:07:09 · 2 answers · asked by yo_pai_1989 2 in Computers & Internet Programming & Design

2 answers

The simplest way to do this is to first break this down into smaller parts.

1.) Computer prime numbers and load results into an array.. Option: Don't compute primes but load an array with prime numbers. Preloading an array with prime number is quicker than computation but will limit your printout lenght to the quantties of prime number loaded.

2.)The pyramid printout is simpler if you consider using an array of numbers and nested looping.

For line = 0 to numberOfLines -1
str = ""
For idx = 0 to line

str = str & array(idx) & " space "

next idx
print str
next line

2007-03-05 14:01:18 · answer #1 · answered by MarkG 7 · 0 0

Dim arr(10) As Integer

For i = 1 To 10
arr(i) = i
Next

For i = 1 To 5
Str1 = ""
For j = 1 To i
Str1 = Str1 & arr(i) & Space(2) Next j
Print Str1
Next

The o/p is like this
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

This is an Example to print such type of Triangle.
Change the code to storee Prime numbes into array.

Other Things works automatically.

2007-03-06 19:07:03 · answer #2 · answered by Ravi Nanjunda Rao 3 · 0 0

fedest.com, questions and answers