輸入整數n,顯示出具有n行的楊輝三角形。vb程式設計,跪求

時間 2021-05-07 20:00:43

1樓:oooo泡

源**如下:

private sub form_click()    n = inputbox("", "", 5)    redim a(n + 1, n + 1), b(n + 1, n + 1)    cls    k = 8    for i = 1 to n    print string((n - i) * k / 2 + 1, " ");    for j = 1 to i    a(i, 1) = 1    a(i, i) = 1    a(i + 1, j + 1) = a(i, j) + a(i, j + 1)    b(i, j) = trim(str(a(i, j)))    print b(i, j); string(k - len(b(i, j)), " ");    next j    print    next iend sub執行程式,在文字框輸入8,再點窗體,效果圖如下:

2樓:遠風的夢想家

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

n = val(inputbox("請輸入"))redim a(n, n)

me.cls

for i = 1 to n

for j = 1 to i

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

else

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

end if

next j

next i

for i = 1 to n

for j = 1 to i

print a(i, j);

next j

print

next i

end sub

3樓:匿名使用者

這些都是我做過的考試要求,- - 不過忘記了

4樓:匿名使用者

''輸出楊輝三角形

private sub command1_click()dim x as string, i as integer, j as integer, n as integer

dim a() as integer

n = val(inputbox("請輸入行數:"))redim a(1 to n, 1 to n)for i = 1 to n

for j = 1 to i

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

else

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

end if

next j

next i

for i = 1 to n

x = ""

for j = 1 to i

x = x & a(i, j) & space(1)next j

print space(n - i + 5) & x & chr(13)

next i

end sub

'除錯成功

5樓:匿名使用者

private sub yh(byval n as integer)dim a(n, n) as integerfor i as integer = 0 to na(i, 0) = 1

next

for i = 0 to n - 1

for j as integer = 1 to ia(i, j) = a(i - 1, j - 1) + a(i - 1, j)

next

next

label1.text = ""

for i = 0 to n - 1

for j = 0 to i

label1.text += a(i, j).tostring() + " "

next

label1.text += vbcrlfnext

end sub

輸入一個小於10的正整數n,顯示具有n行的楊輝三角。。求程式設計!!

6樓:匿名使用者

#include

using namespace std;

//pl是用來求排列數的 jc是用來求階乘的long pl(int,int);

long jc(int);

int main()

return 0;

}//求排列數

long pl(int m,int n)

//求階乘

long jc(int p)

//經測試,輸入的n<=13時都沒有問題

//如果再大一點,就要把程式裡面部分long替換成float或者double

7樓:匿名使用者

#include

#define n 3

int main()

printf("%d\n",sum);

return 0;}

8樓:匿名使用者

#include

int main()

}void int c(int x,int y) /*求楊輝三角形中第x行第y列的值*/

這個改改就行了

從鍵盤輸入正整數n,計算並顯示其階乘值

include unsigned long long fact int n int main void printf 請輸入一個不大於20的正整數 printf n 再見 n return 0 unsigned long long fact int n 注意 printf 本機 ullong max...

輸入整數n顯示出具有n行的楊輝三角形

總有點數學小感悟 dim arryanghui 10,10 dim i,j for i 1 to 10 arryanghui i,1 1 arryanghui i,i 1 next for i 2 to 10 for j 2 to i 1 arryanghui i,j arryanghui i 1,...

pascal輸入整數n,請你判斷n是否是質數。輸入數n,如果是質數則輸出yes否則輸出no用break語句

program t1 varn,i longint f boolean begin readln n i 2 f true while i trunc sqrt n and f doif n mod i 0 then f falseelse inc i if f then writeln yes e...