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

可編程計算器怎麼實現

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

閱讀全文

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

熱點內容
javacapsule 瀏覽:20
extjs按鈕垂直居中 瀏覽:163
ibjsx 瀏覽:647
直銷可編程直流電源哪裡買 瀏覽:952
蘋果6qq錄音文件聽不了 瀏覽:6
網路線怎麼拔 瀏覽:328
webclip文件有什麼危害 瀏覽:700
創維32e360e怎麼看網路電視 瀏覽:824
js網站載入動畫 瀏覽:411
shelljava 瀏覽:666
系統文件被刪可以還原嗎 瀏覽:835
萬方等網站怎麼下載 瀏覽:857
為什麼電腦文件顯示是寫字板 瀏覽:37
百度網盤打卡壓縮文件 瀏覽:925
英語怎麼讀的網站 瀏覽:115
怎麼遠程改電腦開機密碼 瀏覽:501
可以直接打開壓縮文件的瀏覽器 瀏覽:654
qq相冊一個文件可以存多少張照片 瀏覽:894
淘寶升級是不是免費的 瀏覽:819
西安萬利網路科技有限公司怎麼樣 瀏覽:125

友情鏈接