VB简单的计算机制作加法程序代码

VB简单的计算机制作加法程序代码,第1张

添加3个TEXT,和1个COMMAND按钮,把下面代码复制即可

Private

Sub

Command1_Click()

Text3

=

Val(Text1)

+

Val(Text2)

End

Sub

其中Text1和Text2是你要输入的两个加数,command是把两个数相加,text3是结果

储存大整数很容易 用一个int数组就可以了

例如 array[0] = 1234567890

array[1] = 1234567890

合起来就是 12345678901234567890

运算的时候有点麻烦

不过有个取巧的办法

你读取 12345678901234567890 + 1234567890 的时候 截获 "+"

然后 用 后面的那个1234567890 和 a[0] 相加 如果a[0]超过10位 就把第11位 加到 a[1]里面 做为进位

减法相反即可。

如果是C# msdn 里面有 加减乘除

#include <stdioh>

void main()

{

int a,b,c;//定义三个整数

scanf("%d%d",&a,&b);//输入两个整数

c=a+b;//把a+b的值付给c

printf("这两个数的和是:\n%d+%d=%d",a,b,c);//输出结果

}

求两个数的最大公约数和最小公倍数:

#include "stdioh"

#include "conioh"

main()

{

int a,b,num1,num2,temp;

printf("please input two numbers:\n");

scanf("%d,%d",&num1,&num2);

if(num1<num2)/交换两个数,使大数放在num1上/

{

temp=num1;

num1=num2;

num2=temp;

}

a=num1;b=num2;

while(b!=0)/利用辗除法,直到b为0为止/

{

temp=a%b;

a=b;

b=temp;

}

printf("zuidagongyueshushi:%d\n",a);

printf("zuixiaogongbeishushi:%d\n",num1num2/a);

getch();

}

高精度 1 : 加法

program HighPrecision1_Plus;

const

fn_inp='hp1inp';

fn_out='hp1out';

maxlen=100; { max length of the number }

type

hp=record

len:integer; { length of the number }

s:array[1maxlen] of integer

{ s[1] is the lowest position

s[len] is the highest position }

end;

var

x:array[12] of hp;

y:hp; { x:input ; y:output }

procedure PrintHP(const p:hp);

var i:integer;

begin

for i:=plen downto 1 do write(ps[i]);

end;

procedure init;

var

st:string;

j,i:integer;

begin

assign(input,fn_inp);

reset(input);

for j:=1 to 2 do

begin

readln(st);

x[j]len:=length(st);

for i:=1 to x[j]len do { change string to HP }

x[j]s[i]:=ord(st[x[j]len+1-i])-ord('0');

end;

close(input);

end;

procedure Plus(a,b:hp;var c:hp); { c:=a+b }

var i,len:integer;

begin

fillchar(c,sizeof(c),0);

if alen>blen then len:=alen { get the bigger length of a,b }

else len:=blen;

for i:=1 to len do { plus from low to high }

begin

inc(cs[i],as[i]+bs[i]);

if cs[i]>=10 then

begin

dec(cs[i],10);

inc(cs[i+1]); { add 1 to a higher position }

end;

end;

if cs[len+1]>0 then inc(len);

clen:=len;

end;

procedure main;

begin

Plus(x[1],x[2],y);

end;

procedure out;

begin

assign(output,fn_out);

rewrite(output);

PrintHP(y);

writeln;

close(output);

end;

begin

init;

main;

out;

end

高精度 2 : 减法

program HighPrecision2_Subtract;

const

fn_inp='f:\hp2intxt';

fn_out='f:\hp2outtxt';

maxlen=100; { max length of the number }

type

hp=record

len:integer; { length of the number }

s:array[1maxlen] of integer

{ s[1] is the lowest position

s[len] is the highest position }

end;

var

x:array[12] of hp;

y:hp; { x:input ; y:output }

positive:boolean;

procedure PrintHP(const p:hp);

var i:integer;

begin

for i:=plen downto 1 do write(ps[i]);

end;

procedure init;

var

st:string;

j,i:integer;

begin

assign(input,fn_inp);

reset(input);

for j:=1 to 2 do

begin

readln(st);

x[j]len:=length(st);

for i:=1 to x[j]len do { change string to HP }

x[j]s[i]:=ord(st[x[j]len+1-i])-ord('0');

end;

close(input);

end;

procedure Subtract(a,b:hp;var c:hp); { c:=a-b, suppose a>=b }

var i,len:integer;

begin

fillchar(c,sizeof(c),0);

if alen>=blen then len:=alen { get the bigger length of a,b }

else len:=blen;

for i:=1 to len do { subtract from low to high }

begin

inc(cs[i],as[i]-bs[i]);

if (cs[i]<0) then

begin cs[i]:=10+cs[i]; dec(as[i+1])end;

end;

clen:=len;

end;

function Compare(var a,b:hp):integer;

var len:integer;

begin

if alen>=blen then len:=alen { get the bigger length of a,b }

else len:=blen;

while(len>0) and (as[len]=bs[len]) do dec(len);

{ find a position which have a different digit }

if len=0 then compare:=0 { no difference }

else compare:=as[len]-bs[len];

end;

procedure main;

begin

if Compare(x[1],x[2])<0 then positive:=false

else positive:=true;

if positive then Subtract(x[1],x[2],y)

else Subtract(x[2],x[1],y);

end;

procedure out;

begin

assign(output,fn_out);

rewrite(output);

if not positive then write('-');

PrintHP(y);

writeln;

close(output);

end;

begin

init;

main;

out;

end

高精度3 : 乘法 1 : 高精度数 x单精度数

program HighPrecision3_Multiply1;

const

fn_inp='f:\hp2intxt';

fn_out='f:\hp3outtxt';

maxlen=100; { max length of the number }

type

hp=record

len:integer; { length of the number }

s:array[1maxlen] of integer

{ s[1] is the lowest position

s[len] is the highest position }

end;

var

x,y:hp; { x:input hp ; y:output }

z:integer; { z:input lp }

procedure PrintHP(const p:hp);

var i:integer;

begin

for i:=plen downto 1 do write(ps[i]);

end;

procedure init;

var

st:string;

i:integer;

begin

assign(input,fn_inp);

reset(input);

readln(st);

xlen:=length(st);

for i:=1 to xlen do { change string to HP }

xs[i]:=ord(st[xlen+1-i])-ord('0');

readln(z);

close(input);

end;

procedure Multiply(a:hp;b:integer;var c:hp); { c:=ab }

var i,len:integer;

begin

fillchar(c,sizeof(c),0);

len:=alen;

for i:=1 to len do

begin

inc(cs[i],as[i]b);

inc(cs[i+1],cs[i] div 10);

cs[i]:=cs[i] mod 10;

end;

inc(len); { suppose as[len] can bigger than 9 }

while(len>1) and (cs[len]=0) do dec(len);

clen:=len;

end;

procedure main;

begin

Multiply(x,z,y);

end;

procedure out;

begin

assign(output,fn_out);

rewrite(output);

PrintHP(y);

writeln;

close(output);

end;

begin

init;

main;

out;

end

高精度 4 : 乘法 2 : 高精度数 x 高精度数

program HighPrecision4_Multiply2;

const

fn_inp='f:\hp2intxt';

fn_out='f:\hp4outtxt';

maxlen=100; { max length of the number }

type

hp=record

len:integer; { length of the number }

s:array[1maxlen] of integer

{ s[1] is the lowest position

s[len] is the highest position }

end;

var

x:array[12] of hp;

y:hp; { x:input ; y:output }

procedure PrintHP(const p:hp);

var i:integer;

begin

for i:=plen downto 1 do write(ps[i]);

end;

procedure init;

var

st:string;

j,i:integer;

begin

assign(input,fn_inp);

reset(input);

for j:=1 to 2 do

begin

readln(st);

x[j]len:=length(st);

for i:=1 to x[j]len do { change string to HP }

x[j]s[i]:=ord(st[x[j]len+1-i])-ord('0');

end;

close(input);

end;

procedure Multiply(a,b:hp;var c:hp); { c:=a+b }

var i,j,len:integer;

begin

fillchar(c,sizeof(c),0);

for i:=1 to alen do

for j:=1 to blen do

begin

inc(cs[i+j-1],as[i]bs[j]);

inc(cs[i+j],cs[i+j-1] div 10);

cs[i+j-1]:=cs[i+j-1] mod 10;

end;

len:=alen+blen+1;

{

the product of a number with i digits and a number with j digits

can only have at most i+j+1 digits

}

while(len>1)and(cs[len]=0) do dec(len);

clen:=len;

end;

procedure main;

begin

Multiply(x[1],x[2],y);

end;

procedure out;

begin

assign(output,fn_out);

rewrite(output);

PrintHP(y);

writeln;

close(output);

end;

begin

init;

main;

out;

end

高精度5:除法1:高精度数/单精度数

program HighPrecision3_Multiply1;

const

fn_inp='f:\hp2intxt';

fn_out='f:\hp5outtxt';

maxlen=100; { max length of the number }

type

hp=record

len:integer; { length of the number }

s:array[1maxlen] of integer

{ s[1] is the lowest position

s[len] is the highest position }

end;

var

x,y:hp;

z,w:integer;

procedure PrintHP(const p:hp);

var i:integer;

begin

for i:=plen downto 1 do write(ps[i]);

end;

procedure init;

var

st:string;

i:integer;

begin

assign(input,fn_inp);

reset(input);

readln(st);

xlen:=length(st);

for i:=1 to xlen do { change string to HP }

xs[i]:=ord(st[xlen+1-i])-ord('0');

readln(z);

close(input);

end;

procedure Divide(a:hp;b:integer;var c:hp;var d:integer);

{ c:=a div b ; d:=a mod b }

var i,len:integer;

begin

fillchar(c,sizeof(c),0);

len:=alen;

d:=0;

for i:=len downto 1 do { from high to low }

begin

d:=d10+as[i];

cs[i]:=d div b;

d:=d mod b;

end;

while(len>1) and (cs[len]=0) do dec(len);

clen:=len;

end;

procedure main;

begin

Divide(x,z,y,w);

end;

procedure out;

begin

assign(output,fn_out);

rewrite(output);

PrintHP(y);

writeln;

writeln(w);

close(output);

end;

begin

init;

main;

out;

end

高精度 6 : 除法 2 : 高精度数 / 高精度数

program HighPrecision4_Multiply2;

const

fn_inp='f:\hp2intxt';

fn_out='f:\hp6outtxt';

maxlen=100; { max length of the number }

type

hp=record

len:integer; { length of the number }

s:array[1maxlen] of integer

{ s[1] is the lowest position

s[len] is the highest position }

end;

var

x:array[12] of hp;

y,w:hp; { x:input ; y:output }

procedure PrintHP(const p:hp);

var i:integer;

begin

for i:=plen downto 1 do write(ps[i]);

end;

procedure init;

var

st:string;

j,i:integer;

begin

assign(input,fn_inp);

reset(input);

for j:=1 to 2 do

begin

readln(st);

x[j]len:=length(st);

for i:=1 to x[j]len do { change string to HP }

x[j]s[i]:=ord(st[x[j]len+1-i])-ord('0');

end;

close(input);

end;

procedure Subtract(a,b:hp;var c:hp); { c:=a-b, suppose a>=b }

var i,len:integer;

begin

fillchar(c,sizeof(c),0);

if alen>blen then len:=alen { get the bigger length of a,b }

else len:=blen;

for i:=1 to len do { subtract from low to high }

begin

inc(cs[i],as[i]-bs[i]);

if (cs[i]<0) then

begin cs[i]:=10+cs[i]; dec(as[i+1])end;

end;

clen:=len;

end;

function Compare(const a,b:hp):integer;

var len:integer;

begin

if alen>=blen then len:=alen { get the bigger length of a,b }

else len:=blen;

while(len>0) and (as[len]=bs[len]) do dec(len);

{ find a position which have a different digit }

if len=0 then compare:=0 { no difference }

else compare:=as[len]-bs[len];

end;

procedure Multiply10(var a:hp); { a:=a10 }

var i:Integer;

begin

for i:=alen downto 1 do

as[i+1]:=as[i];

as[1]:=0;

inc(alen);

while(alen>1) and (as[alen]=0) do dec(alen);

end;

procedure Divide(a,b:hp;var c,d:hp); { c:=a div b ; d:=a mod b }

var i,j,len:integer;

begin

fillchar(c,sizeof(c),0);

len:=alen;

fillchar(d,sizeof(d),0);

dlen:=1;

for i:=len downto 1 do

begin

Multiply10(d);

ds[1]:=as[i]; { d:=d10+as[i] }

{ cs[i]:=d div b ; d:=d mod b; }

{ while(d>=b) do begin d:=d-b;inc(cs[i]) end }

while(compare(d,b)>=0) do

begin

Subtract(d,b,d);

inc(cs[i]);

end;

end;

while(len>1)and(cs[len]=0) do dec(len);

clen:=len;

end;

procedure main;

begin

Divide(x[1],x[2],y,w);

end;

procedure out;

begin

assign(output,fn_out);

rewrite(output);

PrintHP(y);

writeln;

PrintHP(w);

writeln;

close(output);

end;

begin

init;

main;

out;

end

;经验证,下式结果正确

;S=86H34H-22H=1B38H-22H=1B16H

code segment

assume cs:code,ds:code

org 100h ;COM格式

start:

push cs

pop ds

mov ax,0e53h ;显示'S'

int 10h

mov al,'=';显示'='

int 10h

call @IN

mov dl,al

mov bl,2ah;""

call show ;显示'H'

call @IN

mov dh,al

mov bl,2dh ;"-"

call show ;显示'H-'

call @IN

mov ah,0

mov bp,ax

mov bl,3dh ;"="

call show ;显示'H='

mov ah,0

mov al,dl ;AL←86H

mov bl,dh ;BL←34H

mul bl ;86H34H

;未考虑不够减的情况

sub ax,bp ;AX←AX-22H

mov cx,4

mov dx,ax

next:

push cx

mov cl,4

rol dx,cl

mov ax,dx

and al,0fh ;取出一位

or al,30h ;二进制转换为Ascii

cmp al,'9';比9小直接显示

jb T2

add al,7 ;是A`F的,加7校正

T2:

mov ah,0eh ;显示Ascii

int 10h

pop cx

loop next ;下一位

mov ax,0e48h ;'H'

int 10h

mov ah,0

int 16h ;暂停

mov ah,4ch

int 21h ;结束

@IN:;可输入两位十六进制数

xor bx,bx ;BX←0

mov cx,4

@1:call input

mov bl,al

shl bl,cl ;BL←BL10H

call input

add al,bl ;AL←两位十六进制数

ret

input: ;仅允许输入并显示0-9和A-F

mov ah,0

int 16h ;无回显键盘输入

cmp al,'0';十六进制数 0-F

jb input ;为有效输入

cmp al,'9'

jbe Q1

and al,0dfh ;大小写,同转为大写

cmp al,'A';"A(a)"

jb input

cmp al,'F';"F(f)"

ja input

Q1:mov ah,0eh

int 10h ;显示有效输入

sub al,30h ;0-9之间,Ascii转换为二进制

cmp al,9

jbe Q3

sub al,7

Q3:ret

show:

mov ax,0e48h ;"H"

int 10h

mov al,bl

int 10h

ret

code ends

end start

以上就是关于VB简单的计算机制作加法程序代码全部的内容,包括:VB简单的计算机制作加法程序代码、求程序设计源代码:大整数加减法程序~~~拜托~~~、简单的C语言加法程序代码都有什么等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/9662554.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-30
下一篇 2023-04-30

发表评论

登录后才能评论

评论列表(0条)

保存