在窗体上输出1~100所有偶数,要求每行输5个

2024-12-13 02:08:14
推荐回答(5个)
回答1:

Private Sub form_click()
Dim i As Integer, j As Integer
For i = 2 To 100 Step 2
j = j + 1
If j = 6 Then
Print
j = 1
Else
End If
Print i;
Next i
End Sub

回答2:

#include"stdio.h"
#include"conio.h"
void
main()
{
int
i,j=0;
for(i=0;i<=100;i++)
{
if(i%2==0)
{
j=j+1;
if(j==10)
{
printf("%d\n",i);
j=0;
}
else
printf("%d\t",i);
}
}
getch();
}
我用的win-tc所以加了getch()这个函数,另外也可以把结果存到数组上再输出等!

回答3:

Private Sub Command1_Click()
Dim i As Integer, j As Integer
For i = 2 To 100 Step 2
Print i;
j = j + 1
If j = 5 Then
j = 0
Print
End If
Next
End Sub

回答4:

for i=2 to 100 step 2
print i;
if i mod 10=0 then print ""
next i

回答5:

dim i as integer
dim strOut as string

for i = 2 to 100 step 2
strOut = strOut & " " & i
if i mod 10 = 0 then
strOut = strOut & vbnewline
end if
next
label1= strOut