Private Sub Command1_Click()
Dim A As Integer, B As Integer, C As Integer
If Text3Text = "" Then
MsgBox "请输入计算结果!"
Exit Sub
End If
A = Val(Text1Text): B = Val(Text2Text)
C = A + B
If Not C = Val(Text3Text) Then
Command2Enabled = False
Else
Command2Enabled = True
End If
End Sub
Private Sub Command2_Click()
Dim S1 As Integer, S2 As Integer
If Combo1Text = "" Then
MsgBox "请选择算法!"
Exit Sub
End If
Randomize
S1 = Int(Rnd 10 + 1)
Randomize
S2 = Int(Rnd 10 + 1)
ElseIf Combo1Text = "二位数加法" Then
Randomize
S1 = Int(Rnd 100 + 10)
Randomize
S2 = Int(Rnd 100 + 10)
ElseIf Combo1Text = "三位数加法" Then
Randomize
S1 = Int(Rnd 1000 + 100)
Randomize
S2 = Int(Rnd 1000 + 100)
End If
Text1Text = S1
Text2Text = S2
End Sub
Private Sub Form_Load()
Combo1Clear
Combo1AddItem "一位数加法"
Combo1AddItem "二位数加法"
Combo1AddItem "三位数加法"
Command1Caption = "计算"
Command2Caption = "出题"
End Sub
#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();
}
;已实现,下面是完成程序,其中加减比较简单,关键是将结果输出,注释在程序中穿插
code segment
assume cs:code
start:
mov bx,166
mov ax,55
mov cx,44
add bx,ax ;166+55存于BX中
add ax,cx ;55+44存于AX中
sub bx,ax ;结果存于BX中
call bini ;调用bini,将存于BX中的结果按十进制输出到屏幕
mov ah,4ch
int 21h
;-----------------------
;针对多位数,依次分解,然后输出,从最高位开始输出
;为了更好的理解此段程序,最好拿具体数据比如111代入,查看程序的执行流程
bini proc near
;mov cx,1000d
;call bin
mov cx,100d;若结果超过三位数,在此句前面添加类似代码即可,如结果是四位,则添加如上
call bin
mov cx,10d
call bin
mov cx,1d
call bin
ret
bini endp
bin proc near
mov ax,bx
mov dx,0
div cx
mov bx,dx
mov dl,al
add dl,30h
mov ah,02h
int 21h
ret
bin endp
;----------------------
code ends
end start
先输入行数和列数
#include <stdioh>
#include <stdlibh>
void main(void)
{
int i,j;
int row;
int col;
int matrixA;
int matrixB;
int matrixC;
printf("请输入矩阵的行数(row)和列数(col):");
scanf("%d%d",&row,&col);
//给三个矩阵动态分配内存
matrixA = (int)malloc(rowsizeof(int));
for (i=0; i<row; i++)
{
matrixA[i] = (int)malloc(colsizeof(int));
}
matrixB = (int)malloc(rowsizeof(int));
for (i=0; i<row; i++)
{
matrixB[i] = (int)malloc(colsizeof(int));
}
matrixC = (int)malloc(rowsizeof(int));
for (i=0; i<row; i++)
{
matrixC[i] = (int)malloc(colsizeof(int));
}
//A、B随机取值
for (i=0; i<row; i++)
{
for (j=0; j<col; j++)
{
matrixA[i][j] = rand()%100;
matrixB[i][j] = rand()%100;
}
}
printf("matrixA:\n");
for (i=0; i<row; i++)
{
for (j=0; j<col; j++)
{
printf("%4d", matrixA[i][j]);
}
printf("\n");
}
printf("matrixB:\n");
for (i=0; i<row; i++)
{
for (j=0; j<col; j++)
{
printf("%4d", matrixB[i][j]);
}
printf("\n");
}
//矩阵A、B相加
for (i=0; i<row; i++)
{
matrixC[i][j] = 0;
for (j=0; j<col; j++)
{
matrixC[i][j] = matrixA[i][j] + matrixB[i][j];
}
}
printf("matrixC:\n");
for (i=0; i<row; i++)
{
for (j=0; j<col; j++)
{
printf("%4d", matrixC[i][j]);
}
printf("\n");
}
//释放内存
free(matrixA);
free(matrixB);
free(matrixC);
return;
}
如果对你有所帮助,请记得采纳最佳答案,谢谢!
以上就是关于vb问题 做一个加法练习程序全部的内容,包括:vb问题 做一个加法练习程序、简单的C语言加法程序代码都有什么、一个很简单的计算加减法的汇编程序,急求~等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)