标题: 请问一些loop的问题 [打印本页] 作者: kuang 时间: 2010-9-18 01:11 AM 标题: 请问一些loop的问题 本帖最后由 kuang 于 2010-9-18 01:25 AM 编辑
由于时间的关系,逼不得已想问一下第1、2和4要怎样做呢?大概跟我说怎样做也行
Uploaded with ImageShack.us作者: adryn33129 时间: 2010-9-18 01:27 AM
这些全部loop都是用for.....作者: zegwei 时间: 2010-9-18 01:44 AM
图片太小。看不清去作者: Super-Tomato 时间: 2010-9-18 05:56 AM
由于时间的关系,逼不得已想问一下第1、2和4要怎样做呢?大概跟我说怎样做也行
Uploaded with
kuang 发表于 2010-9-18 01:11 AM
去翻翻你的課本如何使用 while 和 do while 吧,這個题目不需要花很長時間做,問題就只是在學習的心态上作者: lord14383 时间: 2010-9-18 07:55 AM 本帖最后由 lord14383 于 2010-9-18 07:57 AM 编辑
第一题
Dim x As Integer = 0
Dim y As Integer = 0
Dim word As String For x = 0 To 4
For y = 4 To x Step -1
word &= "* "
Next
word &= vbCrLf
Next Label1.Text = word作者: lord14383 时间: 2010-9-18 07:58 AM 回复 1#kuang
第二题
Dim x As Integer = 0
Dim y As Integer = 0
Dim word As String For x = 0 To 4
For y = 0 To x
word &= (5 - y) & " "
Next
word &= vbCrLf
Next Label1.Text = word作者: kuang 时间: 2010-9-18 01:16 PM 回复 5#lord14383
第二题
Dim x As Integer = 0
Dim y As Integer = 0
Dim word As String While x < 5
y = 0
While y <= x word &= (5 - y) & " " y = y + 1
End While
word &= vbCrLf
x = x + 1
End While Label1.Text = word 我用的是GUI你是要用command line你就换Label1.Text就好了作者: lord14383 时间: 2010-9-18 09:23 PM 回复 1#kuang
第一题 Dim xx As Integer = 0
Dim x As Integer = 0
Dim y As Integer = 0
Dim word As String = "" While xx < 3
x = 0
y = 0 While x < 5
y = 4
While y >= x word &= "* " y = y - 1
End While
word &= vbCrLf
x = x + 1
End While
xx = xx + 1
word &= vbCrLf End While Label1.Text = word作者: kuang 时间: 2010-9-18 11:49 PM 回复 11#宅男-兜着走
Sub Main()
Dim x As Integer = 0
Dim y As Integer = 0
Dim word As String = ""
While x < 3
y = 0
While y < 6 - x * 2
word &= 6 - x * 2 & " "
y = y + 1
End While
x = x + 1
word &= vbCrLf
End While
Console.Write(word)
Console.Write("Press any key to continue...")
Console.ReadKey()
End Sub
End Module作者: 宅男-兜着走 时间: 2010-9-20 07:24 PM
//不必 Nested Loop 的方法。
Module Module1
Dim maxNum As Integer = 6
Sub Main()
If maxNum <> 0 Then
Dim col As Integer = maxNum
If maxNum Mod 2 = 0 Then
While col <> 0
col = col - 1
Console.Write(maxNum.ToString())
End While
Console.Write(vbCrLf)
End If
maxNum = maxNum - 1
Main()
Else : Console.ReadKey()
End If
End Sub
End Module
复制代码
作者: 宅男-兜着走 时间: 2010-9-20 07:52 PM
// C++ 版本
#include <cstdlib>
#include <iostream>
using namespace std;
int maxNum = 6;
int main(int argc, char *argv[])
{
if(maxNum !=0)
{
int col = maxNum;
if(maxNum % 2 ==0)
{
while(col !=0)
{
col--;
cout<< maxNum;
}
cout<<"\n";
}
maxNum--;
main(argc, argv);
}else
{
system("PAUSE");
return 0;
}
}
复制代码
作者: karkit1990 时间: 2010-10-2 03:47 PM
a)
for (row=5; row>=1; row--)
{
for (col=1; col<=row; col++)
cout<<"*";