導航:首頁 > 源碼編譯 > c語言怎樣編譯簡單計算器

c語言怎樣編譯簡單計算器

發布時間:2022-12-12 05:50:08

A. C語言編寫簡易計算器程序

C語言編寫計算器

B. 用簡單c語言編寫計算器

#include"stdio.h"
/*預處理命令*/
void
main()
/*主函數*/
{
double
a,b;
/*雙精度實型變數說明*/
char
c,d;
/*變數說明*/
do
/*循環體*/
{
printf("input
a
(-*/)b\n");
/*輸入提示*/
scanf("%lf%c%lf",&a,&c,&b);
/*輸入算術表達式*/
if(c=='
')
/*判斷
*/
printf("=%0.2f",a
b);
/*輸出a
b的值*/
else
if(c=='-')
/*判斷-*/
printf("=%0.2f",a-b);
/*輸出a-b的值*/
else
if(c=='*')
/*判斷**/
printf("=%0.2f",a*b);
/*輸出a*b的值*/
else
if(c=='/')
/*判斷/*/
printf("=%0.3f",a/b);
/*輸出a/b*/
else
/*不滿足以上條件*/
printf("error");
/*輸出錯誤*/
printf("\n\ninput\n");
/*輸入\n*/
scanf("%c",&d);
/*輸入符號給d*/
}
/*循環體結束*/
while(d=='\n');
/*循環條件語句*/
}

C. 用c語言編寫計算器

#include <stdio.h>
struct s_node
{
int data;
struct s_node *next;
};
typedef struct s_node s_list;
typedef s_list *link;
link operator=NULL;
link operand=NULL;

link push(link stack,int value)
{
link newnode;

newnode=(link) malloc(sizeof(s_list));
if(!newnode)
{
printf("\nMemory allocation failure!!!");
return NULL;
}
newnode->data=value;
newnode->next=stack;
stack=newnode;
return stack;
}

link pop(link stack,int *value)
{
link top;
if(stack !=NULL)
{
top=stack;
stack=stack->next;
*value=top->data;
free(top);
return stack;
}
else
*value=-1;
}

int empty(link stack)
{
if(stack==NULL)
return 1;
else
return 0;

}

int is_operator(char operator)
{
switch (operator)
{
case '+': case '-': case '*': case '/': return 1;
default:return 0;
}
}

int priority(char operator)
{
switch(operator)
{
case '+': case '-' : return 1;
case '*': case '/' : return 2;
default: return 0;
}
}

int two_result(int operator,int operand1,int operand2)
{
switch(operator)
{
case '+':return(operand2+operand1);
case '-':return(operand2-operand1);
case '*':return(operand2*operand1);
case '/':return(operand2/operand1);
}
}

void main()
{
char expression[50];
int position=0;
int op=0;
int operand1=0;
int operand2=0;
int evaluate=0;

printf("\nPlease input the inorder expression:");
gets(expression);

while(expression[position]!='\0'&&expression[position]!='\n')
{
if(is_operator(expression[position]))
{
if(!empty(operator))
while(priority(expression[position])<= priority(operator->data)&&
!empty(operator))
{
operand=pop(operand,&operand1);
operand=pop(operand,&operand2);
operator=pop(operator,&op);
operand=push(operand,two_result(op,operand1,operand2));
}
operator=push(operator,expression[position]);
}
else
operand=push(operand,expression[position]-48);
position++;
}
while(!empty(operator))
{
operator=pop(operator,&op);
operand=pop(operand,&operand1);
operand=pop(operand,&operand2);

operand=push(operand,two_result(op,operand1,operand2));
}
operand=pop(operand,&evaluate);
printf("The expression [%s] result is '%d' ",expression,evaluate);
getch();
}

D. C語言編寫簡單的計算器

#
#include<stdio.h>
void main()
{
float a,b;
char d;
printf("請輸入兩個數a,b:");
scanf("%f,%f"&a,&b);
printf("請輸入符號d");
scanf("%c",d);
switch(d)
{
case'+':printf("%f\n,a+b);break;
case'-':printf("%f\n,a-b);break;
case'*':printf("%f\n,a*b);break;
case'/':printf("%f\n,a/b);break;
default:printf("input error\n");
}
}

E. 如何用C程序編寫一個計算器

F. 怎樣用C語言編寫一個簡單的可以進行加減乘除運算混合運算的計算器

用C語言編寫一個簡單的可以進行加減乘除運算混合運算的計算器的方法:

1、打開visual C++ 6.0-文件-新建-文件-C++ Source File;

G. 用c語言 (c++) 編寫計算器程序

我們平時進行數學運算都是用計算器完成的,那麼如何用C語言編寫一個計算器呢?下面我給大家分享一下。

工具/材料

Dev C++

H. C語言編寫一個簡單的計算器

我給你寫一個簡單的計算器程序,你可以看一下。如果需要更多的功能,那麼還要更復雜一些。不是一句話可以說明白的。要用到很多函數的調用,和函數的方法。
#include
"stdio.h"
void
main()
{
int
a,b,result;
char
m;
printf("請輸入需要計算的數:\n");
scanf("%d
%d",&a,&b);
printf("請輸入加、減、乘或除\n");
scanf("%c",&m);
if(m=="+")
//判斷是否進行加法運算,以下同理
result=a+b;
else
if(m=="-")
result=a-b;
elsee
if(m=="*")
result=a*b;
else
if(m=="/")
result=a/b;
else
printf("您輸入有誤\n");
//如果輸入的符號非加減乘或是除,報錯
printf("計算結果為:%d\n",result);
//最後輸出結果
}

I. 如何用C語言寫一個簡易計算器

#include<stdio.h>
int main()
{
double num1;
double num2;
double result;
char ch;
printf("Please enter express to caculate, 'q' to exit(eg. 1+3):");
while(scanf("%lf%c%lf",&num1,&ch,&num2) == 3)
{
switch(ch)
{
case '+':
{
result = num1 + num2;
break;
}
case '-':
{
result = num1 - num2;
break;
}
case '/':
{
if(num2 == 0)
printf("Error:div/0\n");
else
result = num1 / num2;
break;
}
case '*':
{
result = num1 * num2;
break;
}
}
printf("%g%c%g=%g\n",num1,ch,num2,result);
printf("Please enter express to caculate, 'q' to exit(eg. 1+3):");
}
return 0;
}

閱讀全文

與c語言怎樣編譯簡單計算器相關的資料

熱點內容
python復合型數據類型 瀏覽:375
登錄伺服器發生錯誤怎麼回事 瀏覽:272
松下空氣能壓縮機 瀏覽:938
萬能源碼播放器 瀏覽:968
串口伺服器如何轉發 瀏覽:359
如何下載Ck電影部app 瀏覽:744
解壓文具筆袋簡單 瀏覽:288
android百度坐標轉換 瀏覽:367
文件公私鑰加密傳輸 瀏覽:665
python矩陣維度 瀏覽:927
華佗舌診源碼 瀏覽:897
解壓壓縮包有一個錯誤怎麼辦 瀏覽:966
怎麼在手機上設立文件夾 瀏覽:232
雲幫手伺服器搭建教程 瀏覽:785
惠普默認存在哪個文件夾 瀏覽:493
建立桌面圖標文件夾 瀏覽:86
python怎麼跳過異常繼續執行 瀏覽:315
單片機驅動可控硅 瀏覽:294
遼寧沈陽最新代理伺服器ip地址 瀏覽:565
如何安裝用友通伺服器 瀏覽:827