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

可編程計算器怎麼實現

發布時間: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();
}

閱讀全文

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

熱點內容
js翻譯德語 瀏覽:33
從哪裡可以下載a股的數據 瀏覽:437
邏輯文件名和物理文件名關系 瀏覽:66
怎麼查一個網站的外鏈 瀏覽:675
linux下db2安裝時版本選擇 瀏覽:738
匯編編程用哪個軟體 瀏覽:486
仙樂下的歌在文件管理哪裡 瀏覽:477
115網盤解析工具2014 瀏覽:371
內圓弧銑刀怎麼編程 瀏覽:410
記事本文件轉word格式對齊 瀏覽:300
excel刪除恢復文件 瀏覽:290
三星s4怎麼切換3g網路 瀏覽:994
什麼是網站維護 瀏覽:314
文件夾錄像在哪裡 瀏覽:621
可以發語音的是什麼app 瀏覽:804
恢復手機桌面文件管理 瀏覽:627
用什麼軟體可以打開psd文件 瀏覽:459
公安有哪些警務app 瀏覽:150
生意轉租用什麼app 瀏覽:683
廣義的網路信息保密性是指 瀏覽:657

友情鏈接