C語言程式設計中,怎樣使輸出的加減乘除是運算子

時間 2022-02-09 10:15:15

1樓:匿名使用者

#include

#include

#define n 100

typedef structstacks,*lists;

typedef structstack,*list;

int init(list p); //stack 初始化

int inits(lists p); //stacks 初始化

int pushs(lists p,float m); // stacks 入棧

int push(list p,char c); //stack 入棧

int pops(lists p,float *m); //stacks 出棧

int pop(list p,char *c); //stack 出棧

int in(char c); //判斷c是否為資料 是則返回 1 否則 返回 0

char pre(char s,char c); //判斷s c的優先順序 s>c return '>'; slen=0;

return 1;

}int inits(lists p)

p->len=0;

return 1;

}int pushs(lists p,float m)

p->d[p->len++]=m; return 1;

}int push(list p,char c)

p->c[p->len++]=c; return 1;

}int pops(lists p,float *m)

*m=p->d[--p->len]; return 1;

}int pop(list p,char *c)

*c=p->c[--p->len]; return 1;

}int in(char c)

char pre(char s,char c)

if((s=='*')||(s=='/'))

if(s=='(')

if(s==')')

r=k;

if(s=='#')

return r;

}float operate(float a,char t,float b)

float value(char s)

輸出一個操作符和兩個資料

運算

}return opnd.d[opnd.len-1]; //返回表示式的值}

2樓:匿名使用者

應該是輸入加減乘除運算子吧就是直接輸入計算表示式吧這個需要你自己定義,檢測表示式中的字元,是數字正常,是加減乘除則變為加減乘除,你輸入的加減乘除號,系統是不認的,只有讓系統自己輸入就行了,不過這個有點難,要涉及到巨集定義,還要判斷符號優先順序……

3樓:匿名使用者

printf("a+b=%d",a+b);

顯示的結果就是a+b=值

4樓:匿名使用者

printf("+ - * /");

就是寫在引號裡

用c語言編一個計算器程式,能夠實現基本的加減乘除,能夠輸出運算物件,運算子,運算結果。謝謝啦!

5樓:天雨下凡

#include

int main(void)

return 0;}

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

6樓:4747哦

#include

main()

if(ch=='/')

}if(ch=='+')

if(ch=='-')} }

c語言實現加減乘除運算

7樓:匿名使用者

按照你的程式執行後。。。在輸入c值的時候

程式直接結束了。。。還有就是每個case語句後記著加上break跳出不過也有不過根據具體需要也可以不加break;但是你的這個程式需要加上break;

原因是:回車符也是字元,所以你按回後,程式以為是輸入了c的值了,而在輸入b值成功是因為

回車符不是數字形式的。

以下是我改過的程式,編譯執行都很好的

#include

#include

void main()

//為了好看

printf("\n");}

8樓:魏天偉

改成「for(;y==『y』;)」就可以了的!for語句的三個引數,第一個是進行初始化的,第二個是用來判斷的,第三個是在語句最後進行運算的。不懂可以追問,望採納!

9樓:匿名使用者

while迴圈改成for迴圈就可以了。

用 for(;y=='y';) 替換while(y=='y')即可。

10樓:s_b傻瓜公子

原因是因為你輸入完'b'之後,按回車,編譯器會把回車鍵當做是'c'說輸入的內容,所以會出錯。

我改了一下,你可以看到可以輸入並算出結果,但輸入有點難看,如(2 1+),'1'和'+'之間不要加任何東西。你可以自己再想想怎麼改吧,考試中。

程式如下:

#include

#include

void main()

case '-':

case '*':

case '/':

default: break;}}

11樓:渠濟

#include

#include

void main()

}---------------------在每一個case後面都要加上break,否則回貫穿到下一case語句中

12樓:蒼紫幽藍

#include

void main()

printf("...."); //和原來一樣printf("是否繼續");//和原來一樣} }

13樓:

#include

#include

#include

void main()

}這個是對的,試試。

用c語言怎樣實現計算器加減乘除功能?

14樓:匿名使用者

我學c++時寫的

#include

#include "string"

int    count(int a,int b,char c)void main()

; char sign[10];

int i,j=0,k=0,m;

int strlong=strlen(str);//#include "string"

cout<='0'&&str[i]<='9')number[j]=number[j]*10+str[i]-48;

else }

j++;

//cout<

2.堆疊

#include "string"

#include "iostream"

#include

#include

#include

using namespace std;

//自定義型別 用於儲存 兩種資料型別

class  newtype

data;

}; //將字串轉換為 數字陣列和字元陣列  (通用提取字串中數字)

這裡要使用引用

flag=false;

} else

}//for

return true;

} //計算沒有括號的表示式

計算四者表示式  無括號型別  1+2*3+4int ii=0;

//先計算乘除

while(iiall,float &value){

int pos=0;

vectornumbers;

vectorchars;

float va=0;

for(int i=0;inumbers;

vectorchars;

vectorall;

couvert(str, numbers, chars,all);

for(int i=0;i

這是我翻家底找到的 .

15樓:匿名使用者

#include

void main()

scanf("%d\n",&d);}

16樓:沐星辰曦

#include

void main()

17樓:sky思念很淺

#include

void main()}

18樓:

我有個vc++的 任意進位制轉換----棧的連結儲存/* 棧的連結儲存----任意進位制轉換*/#include

#include

typedef int elemtype;

struct snode ;

void initstack(snode*& hs)// 壓棧 插入元素

void push(snode*& hs, const elemtype& item)

//從棧中刪除一個元素並返回該元素

elemtype pop(snode*& hs)//讀取棧頂元素

elemtype peek(snode* hs)bool emptystack(snode* hs)void clearstack(snode*& hs)hs = null;

}void transform(long number, int r)

while(!emptystack(a))

19樓:匿名使用者

#include

int main()

if(b!=0) //如果除數不為0return 0;}

20樓:匿名使用者

#include

#include

int main()

printf("%f%c%f=%f",a,b,c,d);

return 0;}

用c語言編寫一個能加減乘除的程式? 10

21樓:死亡盛世

能加減乘除的程式,這麼略啊,+-*/,這根本沒法回答。

22樓:匿名使用者

看看這個是不是你要的。

23樓:魏子棟

要高精度嗎,還是做計算器

c語言的加減乘除是怎麼實現的

24樓:

本質上都是位運算。 加法通過異或、且和左移遞迴實現。

設a,b為兩個二進位制數,則a+b = a^b + (a&b)<<1;

典型的實現**:

//遞迴版本的加法

int add(int a, int b)//迭代版本

int add_iter(int a, int b)return ans;

}再用加法和移位就能模擬乘除和減法

減法:a-b  = a+(-b)

乘法運算:原理上還是通過加法計算,將b個a相加。

除法運算:除法運算是乘法的逆。看a最多能減去多少個b

25樓:匿名使用者

int a=98, b=33;

c語言程式:輸入運算子,對二個整數進行加減乘除,輸出結果。輸入其他符號,則輸error。

C語言程式設計 兩矩陣加減乘,轉置,讀入,儲存,要求有選單

發給你了 有錯找我 選單自己弄,就給你個範例。可以實現矩陣加,減,乘,及轉置 兩個檔案,一個叫matrix.h,一個叫matrix.cpp matrix.h ifndef matrix h define matrix h include include include include class m...

7用C 程式設計就前20項的和,用C語言程式設計輸出數列1,1,2,3,5,8,13,21的前20 項

include using namespace std bool isprime int n return 1 int main cout sum endl 倒黴熊 include using namespace std const int num 20 int main a n i n i if ...

C語言,求1 3 5n的程式設計,怎樣利用C語言程式設計求1 3 5 N 的值?

庚午子李 有技術含量的,遞迴求解 include int a int n void main 給你個完整點吧 include int main while n 2 0 for int sum 0,i 1 i n i 2 sum i printf sum d n sum return 0 扛菸頭的大槍...