博文
9*9乘法表-3(2007-08-31 20:05:00)
摘要:
# include<iostream.h>
void main()
{
cout<<"*"<<" ";
for(int i=1;i<=9;i++)
cout<<i<<" ";
cout<<endl;
for(int row=1;row<=9;row++)
{
cout<<row<<" ";
for(int j=1;j<=(row-1)*4;j++)//控制空格数
cout<<" ";
for(int col=row;col<=9;col++)
{
if(col*row<10)
cout<<col*row<<" ";
else
cout<<col*row<<" ";
}
cout<<endl;
}
}......
变幻魔方(2007-08-28 20:35:00)
摘要:
实现代码为:
Option Explicit
Private Sub Form_Load()
Label1(0).Visible = False
Dim mytop As Integer, myleft As Integer
Dim i As Integer, j As Integer, k As Integer
mytop = 0
For i = 1 To 8
myleft = 0
For j = 1 To 8
k = (i - 1) * 8 + j
Load Label1(k)
Label1(k).BackColor = IIf((i + j) Mod 2 = 0, vbWhite, vbBlack)
Label1(k).Visible = True
Label1(k).Caption = ""
Label1(k).Top = mytop
Label1(k).Left = myleft
myleft = myleft + Label1(0).Width
Next j
mytop = mytop + Label1(0).Height
Next i
End Sub
Private Sub Label1_Click(Index As Integer)
Dim i As Integer, j As Integer, k ......
P74 4.3(2007-08-23 20:27:00)
摘要:
P74 4.3
# include<iostream.h>
int cube(int n)//求立方
{
return n*n*n;
}
void main()
{
for(int i=100;i<999;i++)
{
int num=i; //保存i的初值;
int a,b,c;//分别表i的个位,十位,百位
c=num/100; //得到百位
num=num%100;//改变i值为两位数
b=num/10;
a=num%10;
if(cube(a)+cube(b)+cube(c)==i)
cout<<"得到的水仙花数为:"
<<i<<endl;
}
}......
P74 4.2(2007-08-23 20:26:00)
摘要:
P74 4.2
# include<iostream.h>
int Factorial(int num)
{
if(num==1)
return 1;
else
return num*Factorial(num-1);
}
void main()
{
long int sum=0;
for(int i=1;i<=15;i++)
sum+=Factorial(i);
cout<<"计算结果为:"
<<sum<<endl;
}......