VB programming prints n layer pyramid rows Yang Hui triangle

Updated on tourism 2024-05-28
5 answers
  1. Anonymous users2024-02-11

    Based on the above, spaces are added to make it look more like a pyramid.

    private sub form_click()const n = 10

    dim a(n, n) as integerdim i, j as integer

    a(1, 1) = 1

    a(2, 1) = 1

    a(2, 2) = 1

    for i = 3 to n

    a(i, 1) = 1

    a(i, i) = 1

    for j = 2 to i - 1

    a(i, j) = a(i - 1, j - 1) +a(i - 1, j)

    next j, i

    for i = 1 to n

    print space(2 * n - 2 * i);

    for j = 1 to i - 1

    print a(i, j);

    next j

    printnext i

    end sub

  2. Anonymous users2024-02-10

    private sub form_click()dim a() as long, n as long, i as long, j as long, x as long

    n = val(

    if n > 16 or n <= 0 thenmsgbox "The number is incorrect, and the number of rows is re-entered"

    exit sub

    end if

    redim a(n, n)

    for i = 1 to n

    for j = 1 to i

    if j = 1 or i = j thena(i, j) = 1

    elsea(i, j) = a(i - 1, j - 1) +a(i - 1, j)

    end if

    next j

    next i

    for i = 1 to n

    print spc(48 - 3 * i);

    for j = 1 to i

    print a(i, j);

    x = len(cstr(a(i, j)))if x = 1 then print spc(3);

    if x = 2 then print spc(2);

    if x = 3 then print spc(1);

    next j

    printprint

    next i

    end sub

  3. Anonymous users2024-02-09

    public class yanghui

    elsenum[m][n]=num[m-1][n-1]+num[m-1][n];This is the recursive method, for example, the coordinates of 3=1+2,3 are 3[3,1]=1[2,0]+2[2,1]; }

    for(int i=0;i;Wrap lines for each layer}}}

  4. Anonymous users2024-02-08

    **:#include

    #define n 10

    void setdata(int(*s)[n],int n);

    int i=0;

    int j=0;

    for(i=0;iarr[0]=1;

    arr=1;

    for(i=2;ifor(j=1;jarr[j]=arr[i-1][j-1]+arr[i-1][j];

    for(i=0;ifor(j=0;j<(2*line-2*i);j++)

    printf("");

    for(j=0;j<=i;j++)

    printf("%4d",arr[j]);

    printf("");

    return 0;

    Method 3: Define CRT Secure No Warnings 1

    #include

    int main()

    int i,j,n=0;

    First, define the two-dimensional array counting symbols i, j and initialize the number of rows in Yang Hui's triangle.

    int a[100][100]=;

    There are only 2 initial values, i.e., a[0][0]=1 and a[0][1]=2, and the initial values of the rest of the array elements are all 0

    The size of the 2D array can be customized, but remember not to make it larger than the size of the integer array.

    while(n<1||n>100)

    Automatically initialize the issue when the entered value is incorrect, re-entering.

    printf("Please enter the number of Yang Hui triangle rows to print":");

    scanf("%d",&n);

    for(i=1;ifor(j=1;j<=i;j++) The second layer of circular borrowing i limits the number of characters per line.

    a[j]=a[i-1][j-1]+a[i-1][j];

    for(i=1;ifor(j=1;j<=i;j++)

    printf("%5d",a[j]);

    printf("");

    return 0;

  5. Anonymous users2024-02-07

    With a dynamic two-dimensional array, two loops are sufficient, assuming that the subscript Wei ij, one number is equal to the sum of the two numbers on his shoulder.

Related questions
12 answers2024-05-28

Not sure what it does?

What are the specific requirements. >>>More

5 answers2024-05-28

Isn't it equivalent to data sorting? sql ?

3 answers2024-05-28

private sub timer1_timer()= "Current Time:" + cstr(time)if = cstr(time) thenmsgbox "The countdown ends" >>>More

10 answers2024-05-28

Set the focus. For example, if you make the text box text1 focus in the program, you can enter the text directly in the text box without clicking the text box with the mouse to make it focus before entering the content. >>>More

2 answers2024-05-28

The odd Rubik's Cubes are arranged on a square matrix of nxn (n is an odd number), which requires the sum of each row, column and diagonal to be the same. As shown in the figure below, it is an odd Rubik's cube with n=5. >>>More