2024-04-30 19:13:36 | 新橄榄网
#include
using namespace std;
int main(void)
{
int x = 0,y = 0;
cout << "请输入相乘的两个数:" << endl;
cin >> x >> y;
cout << "两个数的乘积为:" << x*y << endl;
return 0;
}
这是C++版本,如果你要C语言版本也可以追问
#include
#include
#include
double EPS=10E-6;
double sum(double a,double b)新橄榄网
{
return a+b;
}
double sub(double a,double b)
{
return a-b;
}
double mul(double a,double b)
{
return a*b;
}
double divv(double a,double b)
{
return a/b;
}
int rem(int a , int b)
{
return a%b;
}
int addnumber(int c,int d)
{
int sum=0;
for(int i=c;i<=d;i++)
{
sum+=i;
}
return sum;
}
int factor(int n)
{
int f=1;
for(int i=1;i<=n;i++)
{
f*=i;
}
return f;
}
void displaymenu()
{
printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \n");
printf("*############高级计算器############* \n");
printf("************************************ \n");
printf("* ①加法运算 * \n");
printf("* ②减法运算 * \n");
printf("* ③乘法运算 * \n");
printf("* ④除法运算 * \n");
printf("* ⑤取余运算 * \n");
printf("* ⑥累加运算 * \n");
printf("* ⑦阶乘运算 * \n");
printf("* ⊙结束运算 * \n");
printf("************************************ \n");
printf("************************************ \n");
}
void main()
{
int c,d; /*用于做四则运算的两个数值的说明*/
double a,b; /*用来做累加函数的两个参数值的说明*/
int intresult;
double result; /*用于保存表单运算中函数的返回值*/
int choice;
displaymenu();/*保存用户选择项目菜单项*/
while(1)
{
printf("请选择你所进行运算项目的符号:");
scanf("%d",&choice);
switch(choice)
{
case 1: /*加法计算*/
printf("请输入两个数字:");
scanf("%lf%lf",&a,&b);
result=sum(a,b);
printf("%lf+%lf的计算结果是:%lf\n",a,b,result);
break;
case 2: /*减法计算*/
printf("请输入两个数字:");
scanf("%lf%lf",&a,&b);
result=sub(a,b);
printf("%lf-%lf的计算结果是:%lf\n",a,b,result);
break;
case 3: /*乘法计算*/
printf("请输入两个数字:");
scanf("%lf%lf",&a,&b);
result=mul(a,b);
printf("%lf*%lf的计算结果是:%lf\n",a,b,result);
break;
case 4: /*除法计算*/
{
scanf("%lf%lf",&a,&b);
if(b-0.0
else
{
printf("请输入两个数字:");
result=divv(a,b);
printf("%lf/%lf的计算结果是:%lf\n",a,b,result);
}
break;
}
case 5: /*取余计算*/
printf("请输入两个数字:");
scanf("%d%d",&c,&d);
result=rem(c,d);
printf("%d % %d的计算结果是:%d\n",c,d,result);
break;
case 6: /*累加计算*/
printf("请输入两个整数");
scanf("%d%d",&c,&d);
intresult=addnumber(c,d);
printf("%d-%d的累加计算结果是:%d\n",c,d,intresult);
break;
case 7: //阶乘计算
{
printf("请输入一个大于0小于10的整数字");
scanf("%d",&c);
if(c<0||c>10)
{
printf("请输入一个大于0小于10的整数字,数据错误。\n");
break;
}
intresult=factor(c);
printf("%d的阶乘计算结果是:%d\n",c,intresult);
break;
}
case 0:
printf("谢谢使用。欢迎下次再用。\n");
return ;
default:
printf("选择错误,程序结束\n");
break;
}
}
}
代码如下:
Dim t, t1 As Integer
Dim x, y As Double
Public Sub com()
x = Val(l1.Caption)
Select Case t1
Case Is = 1: y = y + x
Case Is = 2: y = y - x
Case Is = 3: y = y * x
Case Is = 4: y = y / x
End Select
t1 = 0
t = 0
l1.Caption = "0"
End Sub
Private Sub Form_Load()
x = 0
y = 0
t = 0
t1 = 1
End Sub
Private Sub c0_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "0"
Else
l1.Caption = l1.Caption + "0"
End If
End Sub
Private Sub C1_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "1"
Else
l1.Caption = l1.Caption + "1"
End If
End Sub
Private Sub c10_Click(Index As Integer)
If t = 0 Then
l1.Caption = l1.Caption + "."
t = 1
End If
End Sub
Private Sub C2_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "2"
Else
l1.Caption = l1.Caption + "2"
End If
End Sub
Private Sub C3_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "3"
Else
l1.Caption = l1.Caption + "3"
End If
End Sub
Private Sub C4_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "4"
Else
l1.Caption = l1.Caption + "4"
End If
End Sub
Private Sub C5_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "5"
Else
l1.Caption = l1.Caption + "5"
End If
End Sub
Private Sub C6_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "6"
Else
l1.Caption = l1.Caption + "6"
End If
End Sub
Private Sub C7_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "7"
Else
l1.Caption = l1.Caption + "7"
End If
End Sub
Private Sub C8_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "8"
Else
l1.Caption = l1.Caption + "8"
End If
End Sub
Private Sub C9_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "9"
Else
l1.Caption = l1.Caption + "9"
End If
End Sub
Private Sub z1_Click(Index As Integer)
com
t1 = 1
End Sub
Private Sub z2_Click(Index As Integer)
com
t1 = 2
End Sub
Private Sub z3_Click(Index As Integer)
com
t1 = 3
End Sub
Private Sub z4_Click(Index As Integer)
com
t1 = 4
End Sub
Private Sub z5_Click(Index As Integer)
tmp = Mid(l1.Caption, Len(l1.Caption), 1)
If tmp = "." Then
t = 0
End If
If Len(l1.Caption) = 1 Then
l1.Caption = "0"
Else
l1.Caption = Left(l1.Caption, Len(l1.Caption) - 1)
End If
End Sub
Private Sub z6_Click(Index As Integer)
l1.Caption = "0"
Form_Load
End Sub
Private Sub z7_Click(Index As Integer)
If (l1.Caption <> "0") Then
l1.Caption = "-" + l1.Caption
End If
End Sub
Private Sub z8_Click(Index As Integer)
com
l1.Caption = Str(y)
End Sub
扩展资料
语言缺点
Visual Basic 语言具有不支持继承、无原生支持多线程、异常处理不完善等三项明显缺点,使其有所局限性(此些缺点皆已在 vb .net 获得改进)。
不支持继承
VB 5.0 和 VB 6.0 都是基于对象的编程语言,但是不包含继承特性。VB 中提供了特殊的类的功能,但是还是不能满足程序员的需求。
无原生支持多线程
Visual Basic 对于多线程无原生支持,只能通过Windows API的调用实现,且极其的不稳定。因为在API创建的线程中,并没有自动初始化运行时库,导致部分的函数无法使用。一般的,在VB6等早期的VB开发环境下,使用API创建线程的目的是完成容易使程序假死的大量数据或者逻辑的计算。
异常处理不完善
Visual Basic 中内置异常处理,即使未写异常处理代码,一旦用户出错也会弹出一个明确写出出错原因对话框,接着程序终止。
Visual Basic 中可以使用 Err.Raise抛出异常。对系统及用户抛出的异常的处理常用两种模式:一是使用 On Error Resume Next 处理错误;另一种是使用 On Error Goto 将运行引入错误处理代码。但相对 C++ 等语言而言,这样的异常处理破坏了代码的结构。
参考资料:
百度百科-VB
用C语言写两个计数器的小程序。很多人回家过年了,所以回答少,程序已通过#include<stdio.h>/*第一个程序:*/main(){inti=1,m=0;printf("请输入一个数:\n");while(i!=0){//while循环开始当i等于0时,程序中止;scanf("%d",&i);//从键盘获取数值,如果i=0,则退出并
微信小程序中分数显示实现方法最近在开发一款计算类的微信小程序——茄子计算器。下面的来介绍一下里面分数计算器的实现方法。使用控件:rich-text控件原理:利用rich-text支持Html富文本。用一个两行两列的表格来显示分数,第一列的两行合并显示带分数,第二列的第一行显示分子,第二列的第二行显示分母,将表格的边框不显示,仅显示第一行第二列单元格的下边框线。这样就实现了分数的显
微信小程序代码审核要多久?代码要求是什么?1.其实小程度的审核是根据他官方文档上提的要求进行审核。比如:导航需要明确,来去自如。开发者可根据自身功能设计需要在页面内添加自有导航。并保持不同页面间导航一致。但是受限于手机屏幕尺寸的限制,小程序页面的导航应尽量简单,若仅为一般线性浏览的页面建议仅使用微信导航栏即可。2.如果你的小程序设计的内容复杂,导航复杂,页面操作多尔繁杂,那么审核员肯定不
用JAVA制作一个小程序,计算两个数的加减乘除,用Applet实现下面两个可以么,是我做实验答辩时用到的!importjava.awt.*;//AWT核心包importjava.awt.event.*;//提供事件类和监听器publicclassCounterextendsFrameimplementsActionListener{TextFieldt=newTextF
MATLAB编写一些小程序,求大神1.(1)t=0:2:100;height=2.13*t.^2–0.0013*t.^4+0.000034*t.^4.751;xlswrite(‘A.xls’,[t;height]);(2)fprintf(('t=%f\n',t(find(max(height)))));fprintf(‘height=%f\n’,max(height)
微信小程序怎样推广小程序推广方式。1、附近的小程序(免费),在小程序后台,开通“附近的小程序”,设置门店地理位置,小程序自动展现给周边5km内的微信用户,所有符合条件的小程序能在“附近的小程序”」获得免费曝光,且一个小程序能添加10个地理位置。2、附近的小程序广告(需付费)。附近的小程序是微信开放的关键流量入口,同时开放了广告投放渠道。广告位是在附近小程序的第三行,点击即可打开对
公交乘车码怎么下载使用?公交乘车码是不能下载的。打开公交乘车码方法如下:1、打开手机,找到微信,点击并进入;2、进入之后,找到“小程序”,点击并进入;3、进入之后,搜索“腾讯乘车码”,点击并进入;4、进入之后,即可看到乘车码。腾讯乘车码是一种可用来乘坐交通工具、适用于多个交通场景的二维码,是基于微信小程序开发的服务,2017年7月首次在广州上线。2018年11月
微信小程序无法加载-SSL配置修改近期研究小程序,碰到android上小程序无法加载问题。小程序的后台我们配置了Nginxhttps的反向代理,ssl证书用了Let'sEncrypt证书。开始我们nginx的ssl配置ssl_certificate /etc/letsencrypt/live/fullchain.pem;ssl_certificate_key /e
2023-11-20 19:29:40
2023-11-21 06:00:28
2023-12-03 15:22:45
2023-11-24 21:55:32
2023-10-20 21:49:03
2023-12-09 21:26:50