導航:首頁 > 編程知識 > 可編程計算器怎麼實現

可編程計算器怎麼實現

發布時間:2023-05-25 23:08:46

Ⅰ 用C語言設計並實現一個簡單計算器

額,搞定了。

你冊游交給老師的時候,你要告訴他for循環的功能,for()循環體里也就是for下方{}大括弧里的代碼要被循環執行。然後你就一行一行的州轎銷解釋 switch()里的語句就行了。

break表示跳出switch()。

至於int a,b,i; 這些你肯定懂了的吧。

最後那裡表示在主函數 main()里調用自定義的函數

#include <stdio.h>

int calculator() //定義一個函數。完成計算功能

{

int a,b, i;

char c;

for(i=0;;i++)

{

printf("請輸入所要計算的兩個數,以及所要執行的計算符號 ");

scanf("%d %d %c", &a,&b,&c);

switch (c)

{

case '+':

printf("所要計算的式子:%d+%d ",a,b);

a = a + b;printf("計算結果為:%d ",a);

break;

case '-':

printf("所要計算的式子:%d-%d ",a,b);

a = a - b;printf("計算結果為:%d ",a);

break;

case '*':

printf("所要計算的式子:%d*%d ",a,b);

a = a * b;printf("所要計算的式子:%d*%d ",a,b);printf("計算結果為:%d ",a);

break;

case '/':

printf("所要計算的式子:%d/%d ",a,b);

a = a / b;printf("所要計算的式子:%d/%d ",a,b);printf("計帆察算結果為:%d ",a);

break;

}

}

}

int main()

{

calculator();//在main()函數里調用自定義的函數calculator

}

Ⅱ 如何用c語言實現一個計算器

1、#include<stdio.h>intmain()

2、{inta,b,c;scanf("%d%d%d"盯拆,&a,&b,&c);

3、intsum=a+b+c;

4、printf("和:%d",sum);

5、printf("平均值:%f",sum/3.0);

6、return0

Ⅲ 如何在計算器上編程

可以在手機上安裝可編程的計算器。例如使用易歷知食軟體內部的可編程計算器,就可以在計算器上編程,下面示例是編寫一個計算圓面積的函數c,並在計算器中用函數c來計算半徑為6的圓的面積,如下圖所示:

Ⅳ 用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();
}

閱讀全文

與可編程計算器怎麼實現相關的資料

熱點內容
文件名如何沒有文字 瀏覽:601
吃雞地圖資源包文件路徑 瀏覽:267
cad文件轉移手機 瀏覽:733
指定區域網內文件delphi 瀏覽:638
蘋果5s充電介面維修 瀏覽:913
建行app怎麼老是信息填寫錯誤 瀏覽:832
羅技g903切換配置文件 瀏覽:649
游戲的數據在哪個英文文件夾 瀏覽:435
編程一般學什麼專業課 瀏覽:394
不屬於資料庫系統的主要組成部分 瀏覽:797
jdl是什麼網路詞 瀏覽:247
優酷的緩存視頻文件夾 瀏覽:842
jsp頁面獲取地址欄參數 瀏覽:893
怎麼帶小度app聽酷狗音樂的歌 瀏覽:17
icleanerpro白蘋果 瀏覽:786
2016年1024客戶端安卓 瀏覽:136
win7連接不了網路列印機共享的列印機 瀏覽:214
為啥電腦發文件是rtf格式 瀏覽:927
linux下全局查找一個文件 瀏覽:78
美國是如何實施網路戰 瀏覽:7

友情鏈接