safwan
safwan
Branch Unspecified
23 Jan 2009

Printing pyramid in VB

HI, all i have made a program to print a pyramid in vb0.6 but its looking like:
*
* *
* * *
* * * *
* * * * *
but i need :
-----*
----* *
---* * *
--* * * *
so my code wich i wrot is
Private Sub Command1_Click()
i = 1
For i = 1 To 5
y = 1
For y = 1 To i
Print "*";
Next y
Print
Next i

End Sub
so plz help what will be the code.
😉

😁
safwan

safwan

Branch Unspecified
24 Jan 2009
plese tomorrow is my practical exame for final any body some body just give idea also plese.
shalini_goel14

shalini_goel14

Branch Unspecified
24 Jan 2009
Hi safwan,

Please check the following piece of code, if it can be of any help to you.😀

Private Sub Command1_Click()
a = 1
For a = 1 To 5
b = 1 
For b = 1 To 6-a
Print " ";
Next b
c = 1
For c = 1 To a
Print "*";
Next c
Print
Next a
End Sub
 
Please correct me if any syntax errors. Hope this logic will work for you.😀

[Note : The above code is not compiled and executed. So if any issues let me know. ]
shalini_goel14

shalini_goel14

Branch Unspecified
24 Jan 2009
Re: Printing pyramid in JAVA

For Java users, Pyramid can be make as follows.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package myjava;
/**
 *
 * @author shalinig
 */
public class Pyramid {
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
 
        for (int a = 1; a <= 5; a++) {
 
            for (int b = 0; b <= 5-a; b++) {
                System.out.print(" ");
            }
            for (int c = 1; c <= a; c++) {
                System.out.print("* ");
            }
            System.out.print("\n");
        }
    }
}
 
Output:
*same as asked by safwan*

[Note : This code is well compiled and executed. ]
safwan

safwan

Branch Unspecified
24 Jan 2009
shalini_goel14
Hi safwan,

Please check the following piece of code, if it can be of any help to you.😀

Private Sub Command1_Click()
a = 1
For a = 1 To 5
b = 1 
For b = 1 To 6-a
Print " ";
Next b
c = 1
For c = 1 To a
Print "*";
Next c
Print
Next a
End Sub
 
Please correct me if any syntax errors. Hope this logic will work for you.😀

[Note : The above code is not compiled and executed. So if any issues let me know. ]
Thank you shalini

Share this content on your social channels -

Only logged in users can reply.