重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
下面这段代码,是我用来计算每个月存500元进银行,连续30年,最后连本带利能有多少钱。这里面涉及复利计算。界面中右边的文本框用来输出每一次计算的结果。
创新互联-专业网站定制、快速模板网站建设、高性价比新野网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式新野网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖新野地区。费用合理售后完善,十载实体公司更值得信赖。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim nianxian As Integer '年限变量
Dim dingcun As Integer '定存变量
Dim fuli_big As Long '大复利
Dim fuli_small As Long '小复利
Dim i As Integer '循环变量
Dim DATAstring As String '数据字符串
nianxian = Val(年限_TextBox.Text)
dingcun = Val(定存_TextBox.Text)
DATAstring = ""
For i = 1 To nianxian
fuli_small = dingcun * (1 + 0.1875)
dingcun = fuli_small
fuli_big = fuli_big + fuli_small
DATAstring = DATAstring + "[" + Trim(Str(i)) + "]" + Str(fuli_big) + Chr(13) + Chr(10)
'DATAstring = DATAstring + "[" + Trim(Str(i)) + "]" + Str(fuli_small) + Chr(13) + Chr(10)
Next
'fuli_big = fuli_small
TextBox1.Text = DATAstring
结果_TextBox.Text = Str(fuli_big) + "元"
End Sub
Delphi代码如下:
procedure TForm1.Button1Click(Sender: TObject);
var
购物总价:Integer;
折扣:Extended;
begin
购物总价:=StrToInt(Edit1.Text);
if 购物总价250 then
begin
折扣:=0;
end
else if 购物总价500 then
begin
折扣:=0.05;
end
else if 购物总价1000 then
begin
折扣:=0.075;
end
else if 购物总价2000 then
begin
折扣:=0.1;
end
{
此段的折扣是多少?
else if 购物总价3000 then
begin
折扣:=0.05;
end
}
else if 购物总价=3000 then
begin
折扣:=0.15;
end;
ShowMessage('您享受的折扣是:'+FloatToStr(折扣)
+' 原价:'+IntToStr(购物总价)
+' 折后总价:'+FloatToStr(购物总价*(1-折扣)));
end;
新建窗口,添加picture控件
利用line()方法画线
line(开始x坐标,开始y坐标)-(结束x坐标,结束y坐标),线的颜色,画线的方式(默认为线,B为矩形无填充,BF为填充的矩形)
For i = 1 To 16
Picture1.Line (0, Picture1.Height / 2)-(i * (Picture1.Width / 16), 0), RGB(255, 0, 0)
Picture1.Line (0, Picture1.Height / 2)-(i * (Picture1.Width / 16), Picture1.Height), RGB(255, 0, 0)
Picture1.Line (Picture1.Width, Picture1.Height / 2)-(i * (Picture1.Width / 16), 0), RGB(0, 255, 0)
Picture1.Line (Picture1.Width, Picture1.Height / 2)-(i * (Picture1.Width / 16), Picture1.Height), RGB(0, 255, 0)
Next i
如果要在窗口上画也可以调用窗口的line方法即form.line()
Imports System
Module Program
Sub Main()
Dim n As Integer
n=6
Console.WriteLine("{0}!={1}",n,fact(n))
n=10
For i As Integer=1 To n
Console.Write("{0}{1}",fibo(i),IIF(n=i,vbCrLf,","))
Next
Console.Write("按任意键继续。。。 ")
Console.ReadKey(True)
End Sub
' 递归算阶乘
Function fact(n As Long) As Long
If 0=n OrElse 1=n Then Return 1
Return n*fact(n-1)
End Function
' 递归算斐波那契数列
Function fibo(n As Long) As Long
If 1=n OrElse 2=n Then Return 1
Return fibo(n-1)+fibo(n-2)
End Function
End Module