简单计算器,简单计算器下载免费

简单计算器,简单计算器下载免费缩略图

简单的计算器

简单的计算器

int i; char temp; double result[100],dotvalue=0; for (i=0;i<100;i++) result[i]=0; int ceng=50,dot=0,dotnum=0,type=0,type1=0,ji=0; for (i=0;i10000 || m_float_output<-10000) { MessageBox("结果超出范围!","错误",MB_ICONWARNING|MB_OK); return; }

这是我编写过的一个计算器代码,是直接通过文本框输入算式的那种,你给成按一个键输一个的是一样的。有什么问题可以交流。

简易计算器

简易计算器

加,减,乘,你应该用#define 定义一个简单的字符来表示, scanf("%s",&a),这个s建议写成c,其次,数据和对应的运算符(+ – *)只要倒过来运算就可以了,用一个%把对应的数组下表转换一下就可以了,你这写的太复杂,大家都不想看

编写简单计算器

编写简单计算器

#include “stdio.h”

#include “ctype.h”

#include “stdlib.h”

void main (){

int j,i=0,n=0;

double flag,sum=0,buffer;

char sign=’+’,str[50],*p;

gets(str);

while(str[0] != ‘0’) {

do{

j=i;

while(isdigit(str[i++])||str[i]==’.’) n++;

flag = str[i-1];

str[i-1]=’\0′;

p=&str[j];

switch(sign){

case ‘+’: if(str[i]==’*’||str[i]==’/’) buffer = atof(p);

else sum+=atof(p);

break;

case ‘-‘: if(str[i]==’*’||str[i]==’/’) buffer = -atof(p);

else sum-=atof(p);

break;

case ‘*’: if(str[i]==’*’||str[i]==’/’) buffer*=atof(p);

else{

buffer*=atof(p);

sum+=buffer;

}

break;

case ‘/’: if(str[i]==’*’||str[i]==’/’) buffer/=atof(p);

else{

buffer/=atof(p);

sum+=buffer;

}

break;

}

if(flag!=’ ‘) break;

sign=str[i++];

}while(i++);

if(n) printf(“%.2f\n”,sum);

sum=0;

buffer=0.0;

sign=’+’;

i=0;

n=0;

gets(str);

}

}

什么是 简易计算器

一个简单到只有最基础运算的计算器吧.

设计一个简单的计算器。

给你这个你应该就会全部了

#include

//===========================================调用阶乘算法=============

long keven(int n)

{

if (n<0)

printf(“输入错误!”);

//a=-1;

else if (n==0)

return 1 ;

else

return n*keven(n-1);

}

//====================================================================

long main()

{ float a,b,c;

float m,n;

printf(“请选择功能!\n”);

printf(“0代表退出!\n”);

printf(“1代表加法!\n”);

printf(“2代表减法!\n”);

printf(“3代表乘法!\n”);

printf(“4代表除法!\n”);

printf(“5代表阶乘!\n”);

while (1)

{

scanf(“%f”,&a);

if(a==0)

return 0;

if (a==1)

{

scanf(“%f%f”,&b,&c);

printf(“%f+%f=%f”,b,c,b+c);

// break;================如果加上break的话执行一次算法之后就退出来了!=========

}

if (a==2)

{ scanf(“%f%f”,&b,&c);

printf(“%f-%f=%f”,b,c,b-c);

}

if (a==3)

{

scanf(“%f%f”,&b,&c);

printf(“%f*%f=%f”,b,c,b*c);

}

if (a==4)

{

scanf(“%f%f”,&b,&c);

if (c!=0)

{

printf(“%f/%f=%f”,b,c,b/c);

}

else printf(“输入错误!”);

}

if(a==5)

{

int n;

scanf(“%d”,&n);

printf(“%d的阶乘是%ld”,n,keven(n));

}

}

}

用Visual Basic 语言怎样编写简单计算器(记事本 )

Private Sub cmdcalc_Click()

If opernum < 2 Then Exit Sub

Select Case opersymbol

Case 0

num1 = num1 + num2

Case 1

num1 = num1 – num2

Case 2

num1 = num1 * num2

case3

If num2 <> 0 Then

num1 = num1 / num2

Else

MsgBox “除数不能为0”

End If

End Select

opernum = 1

isnumber = True

str2 = “”

str1 = Str(num1)

txtresult = str1

End Sub

Private Sub cmdclear_Click(index As Integer)

Select Case index

Case 0

If opernum = 1 And isnumber And Len(str1) > 0 Then

str1 = Left(str1, Len(str1) – 1)

num1 = Val(str1)

txtresult = str1

elself isnumber And opernum = 2 And Len(str2) > 0

str2 = Left(str2, Len(str2) – 1)

num2 = Val(str2)

txtresult = str1 + str2

End If

Case 1

If isnumber And opernum = 1 Then

str1 = “0”

num1 = 0

txtresult = str1

elself isnumber And opernum = 2

str2 = “”

num2 = 0

txtresult = Str(num1)

opernum = 1

End If

Case 2

txtresult = “0”

str1 = “”

str2 = “”

num1 = 0

num2 = 0

opernum = 1

End Select

End Sub

Private Sub cmddot_Click()

If isnumber Then

If opernum = 1 Then

If InStr(string1, “.”) = 0 Then

str1 = str1 + “.”

txtresult = str1

End If

ElseIf opernum = 2 Then

If InStr(str2, “.”) = 0 Then

str2 = str2 + “.”

txtresult = str1 + str2

End If

End If

End If

End Sub

Private Sub cmdnumber_click(index As Integer)

If isnumber Then

If opernum = 1 Then

str1 = str1 + Right(Str(index), 1)

num1 = Val(str1)

txtresult = str1

ElseIf opernum = 2 Then

str2 = str2 + Right(Str(index), 1)

num2 = Val(str2)

txtresult = str1 + str2

End If

ElseIf Not isnumber Then

isnumber = ture

str1 = str1 + str2 + “”

opernum = 2

num2 = index

str2 = Right(Str(num2), 1)

txtresult = str1 + str2

End If

End Sub

Private Sub cmdoperate_click()(index As Integer)

If isnumber And opernum = 1 Then

isnumber = False

opernum = 2

ElseIf isnumber And opernum = 2 Then

Call cmdcalc_Click

isnumber = False

End If

str2 = “” = cmdoperate(index).Caption

txtresult = str1 + str2

opersymbol = index

End Sub

Private Sub form_load()

opernum = 1

isnumber = True

str1 = “”

str2 = “”

num1 = 0

num2 = 0

txtresult = “”

End Sub

编写一个简单的计算器

楼上不错.完整的应该加上头文件 #include #include int main() {double a,b,r; char c; scanf("%d,%c,%d",&a,&c,&b); switch(c) { case ‘+’: r=a+b;break; case ‘-‘: r=a-b;break; case ‘*’: r=a*b;break; case ‘/’: if(b!=0) r=a/b; else printf("error");break; default:printf("error"); } printf("=%d",r); getch(); return 0; }

如何用vb编写简单计算器

Option Explicit

Dim Op1, Op2 ‘ 前面输入的操作数

Dim DecimalFlag As Integer ‘ 小数点仍然存在吗?

Dim NumOps As Integer ‘ 操作数个数

Dim LastInput ‘ 指示上一次按键事件的类型

Dim OpFlag ‘ 指示未完成的操作

Dim TempReadout

‘ C (取消) 按钮的 Click 事件过程

‘ 重新设置显示并初始化变量

Private Sub Cancel_Click()

Readout = Format(0, “0.”)

Op1 = 0

Op2 = 0

Form_Load

End Sub

‘ CE (取消输入) 按钮的 Click 事件过程

Private Sub CancelEntry_Click()

Readout = Format(0, “0.”)

DecimalFlag = False

LastInput = “CE”

End Sub

Private Sub Command2_Click()

End Sub

‘ 小数点 (.) 按钮的 Click 事件过程

‘ 如果上一次按键为运算符,初始化 readout 为 “0.”;

‘ 否则显示时追加一个小数点

Private Sub Decimal_Click()

If LastInput = “NEG” Then

Readout = Format(0, “-0.”)

ElseIf LastInput <> “NUMS” Then

Readout = Format(0, “0.”)

End If

DecimalFlag = True

LastInput = “NUMS”

End Sub

Private Sub drjsb_Click()

If Readout <> “0” And Readout <> “0.” Then

Form1.Text1.Text = Form1.Text1.Text & Readout

Form1.Text1.SelStart = Len(Form1.Text1.Text)

Form6.Hide

End If

End Sub

‘ 窗体的初始化过程

‘ 设置所有变量为其初始值

Private Sub Form_Load()

DecimalFlag = False

NumOps = 0

LastInput = “NONE”

OpFlag = ” “

Readout = Format(0, “0”)

‘Decimal.Caption = Format(0, “.”)

End Sub

‘ 数字键 (0-9) 的 Click 事件过程

‘ 向显示中的数追加新数

Private Sub Number_Click(Index As Integer)

If LastInput <> “NUMS” Then

Readout = Format(0, “.”)

DecimalFlag = False

End If

If DecimalFlag Then

Readout = Readout + Number(Index).Caption

Else

Readout = Left(Readout, InStr(Readout, Format(0, “.”)) – 1) + Number(Index).Caption + Format(0, “.”)

End If

If LastInput = “NEG” Then Readout = “-” & Readout

LastInput = “NUMS”

End Sub

‘ 运算符 (+, -, x, /, =) 的 Click 事件过程

‘ 如果接下来的按键是数字键,增加 NumOps。

‘ 如果有一个操作数,则设置 Op1。

‘ 如果有两个操作数,则将 Op1 设置为 Op1 与

‘ 当前输入字符串的运算结果,并显示结果

Private Sub Operator_Click(Index As Integer)

TempReadout = Readout

If LastInput = “NUMS” Then

NumOps = NumOps + 1

End If

Select Case NumOps

Case 0

If Operator(Index).Caption = “-” And LastInput <> “NEG” Then

Readout = “-” & Readout

LastInput = “NEG”

End If

Case 1

Op1 = Readout

If Operator(Index).Caption = “-” And LastInput <> “NUMS” And OpFlag <> “=” Then

Readout = “-“

LastInput = “NEG”

End If

Case 2

Op2 = TempReadout

Select Case OpFlag

Case “+”

Op1 = CDbl(Op1) + CDbl(Op2)

Case “-“

Op1 = CDbl(Op1) – CDbl(Op2)

Case “X”

Op1 = CDbl(Op1) * CDbl(Op2)

Case “/”

If Op2 = 0 Then

MsgBox “除数不能为 0”, 48, “计算器”

Else

Op1 = CDbl(Op1) / CDbl(Op2)

End If

Case “=”

Op1 = CDbl(Op2)

Case “%”

Op1 = CDbl(Op1) * CDbl(Op2)

End Select

Readout = Op1

NumOps = 1

End Select

If LastInput <> “NEG” Then

LastInput = “OPS”

OpFlag = Operator(Index).Caption

End If

End Sub

‘ 百分比键 (%) 的 Click 事件过程

‘ 计算并显示第一个操作数的百分数

Private Sub Percent_Click()

Readout = Readout / 100

LastInput = “Ops”

OpFlag = “%”

NumOps = NumOps + 1

DecimalFlag = True

End Sub

C语言实现的简易计算器

展开全部

#include

void main()

{

float a,b,i=0;

char yun;

mama: printf(“\n请输入运算符和要计算的两个数:”);

main:if(i<3)

{

fflush(stdin);

scanf(“%c%f%f”,&yun,&a,&b);

switch(yun)

{

case ‘+’:printf(“%.2f+%.2f=%.2f”,a,b,a+b);

break;

case ‘-‘:printf(“%.2f-%.2f=%.2f”,a,b,a-b);

goto mama;

case ‘*’:printf(“%.2f*%.2f=%.2f”,a,b,a*b);

goto mama;

case ‘/’:printf(“%.2f/%.2f=%.2f”,a,b,a/b);

goto mama;

default:i++;

{ if(i==3)

printf(“\n您已经三次输入不正确:谢谢使用…再见!”);

else

printf(“您的输入有误\n请从新输入:”);

goto main;

}

}

printf(“\n谢谢使用…再见!”);

}

}

1。编写简单计算器

#include using namespace std; double cal(double a, double b, char ch); int main() { double a = 0, b = 0; char ch; double result = 0; while(true ) { cin >> b >> ch; a = cal(a, b, ch); } return 0; } double cal(double a, double b, char ch) { switch(ch) { case(‘q’): { cout << endl << "end of calculations"; exit(0); } case('s'): { cout << endl << "=" << b << endl; return b; } case('+'): { cout <<< "=" << a + b << endl; return a + b; } case('-'): { cout <<< "=" << a - b << endl; return a - b; } case('*'): { cout <<< "=" << a * b << endl; return a * b; } case('/'): { if ( b != 0 ) { cout <<< "=" << a / b << endl; return a / b; } else { cerr << endl << "输入错误,0不能作为被除数!"; exit(0); } } default: { cerr << endl << "输入错入"; exit(0); } } }