題目18 用C語言設計簡單的計算器,要求能夠對輸入的數

2021-07-30 12:58:22 字數 5530 閱讀 7918

1樓:匿名使用者

#include

#include

#include

int deal(int op1,int op2,char op) //運算 }

return op1;

} char *replace(char *source, char *sub, char *rep) //字串替換

else

*pc1++ = *source;

source++;

} *pc1 = null;

return result;

} int main() }

int k = 0;

if(pos != -1) }

else

continue;

} if(tmp != pos && *p != ')')

int start = pos;

while( temp[pos] >= '0' && temp[pos] <= '9')

op1[k] = '\0';

while((temp[pos] >= '0' && temp[pos] <= '9') || temp[pos] == '.')

pos++;

op = temp[pos];

oper1 = atoi(op1);

pos++;

k = 0;

while( temp[pos] >= '0' && temp[pos] <= '9')

op2[k] = '\0';

while((temp[pos] >= '0' && temp[pos] <= '9') || temp[pos] == '.')

pos++;

oper2 = atoi(op2);

int end;

if( temp[pos] != ')')

end = --pos;

else }

char rep[100];

k = 0;

for(; start <= end; start++,k++)

rep[k] = '\0';

fin = deal(oper1,oper2,op);

char final[100];

itoa(fin,final,10);

temp = replace(temp,rep,final);

back = temp;

pos = -1;

p = temp;

k = 0;

*rep = null;

*final = null;

printf("%s\n",replace(temp,rep,final));

} else }

else

continue;

break;

} if(tmp != pos && tmp != (int)strlen(temp)-1)

else

pos = 0;

int start = pos;

while( temp[pos] >= '0' && temp[pos] <= '9')

while((temp[pos] >= '0' && temp[pos] <= '9') || temp[pos] == '.')

pos++;

op1[k] = '\0';

op = temp[pos];

oper1 = atoi(op1);

pos++;

k = 0;

while( temp[pos] >= '0' && temp[pos] <= '9')

op2[k] = '\0';

while((temp[pos] >= '0' && temp[pos] <= '9') || temp[pos] == '.')

oper2 = atoi(op2);

int end = --pos;

char rep[100] = ;

k = 0;

for(; start <= end; start++)

fin = deal(oper1,oper2,op);

char final[100];

itoa(fin,final,10);

temp = replace(temp,rep,final);

back = temp;

for(k = 0; k < (int)strlen(temp); k++)

if(k == (int)strlen(temp))

break;

pos = -1;

p = temp;

k = 0;

printf("%s\n", temp);

} }printf("%d\n",fin);

return 0;}

2樓:河源古天樂啊

#include

int main()

else

break;

}return 0;}

c語言設計一個簡單的計算器程式

3樓:凌亂心扉

#include<stdio.h>//計算器

voidmenu()//自定義的選單介面

{printf("--------------------\n");

printf("請輸入你的選擇\n");

printf("1.+\n");

printf("2.-\n");

printf("3.*\n");

printf("4./\n");

printf("--------------------\n");

}intmain()

{inti=0;

intj=0;

intnum=0;//計算結果存放在nun

intselect=0;//選擇的選項存放在select

do//do-while先執行再判斷迴圈條件,即可實現重複計算功能

{menu();//列印出選單介面

scanf("%d",&select);//輸入你的選項

printf("請輸入計算值:");

scanf("%d%d",&i,&j);//輸入要計算的數值

switch(select)

{case1:

printf("%d+%d=%d\n",i,j,num=i+j);//實現加法功能

break;

case2:

printf("%d-%d=%d\n",i,j,num=i-j);//實現減法功能

break;

case3:

printf("%d*%d=%d\n",i,j,num=i*j);//實現乘法功能

break;

case4:

printf("%d-%d=%d\n",i,j,num=i/j);//實現除法功能

break;

default:

printf("輸入有誤重新選擇");

break;

}}while(select);

return0;

}執行結果:

4樓:憽人邷

/*2023年12月23日 12:43:46

目的:計算器的實現

*/# include

# include

# include

char get_choice(void); //獲取使用者輸入的選項,並建立目

char get_first(void); //獲取使用者輸

入的選項,並剔除錯誤輸入

float get_int(void); //獲取使用者輸入的計算值

float add(void); //定義加法函式

float subtraction(void); //定義減法函式

float multiplication(void); //定義乘法函式

float division(void); //定義除法函式

float extract(void); //定義開方函式

float square(void); //定義平方函式

float cube(void); //定義立方函式

int count = 0;

int main(void)

fflush(stdin);

choice = get_choice();

}printf("bye");

return 0;

}//獲取使用者輸入的選項,並建立目錄

char get_choice(void)

return ch;

}//獲取使用者輸入的選項,並剔除錯誤輸入

char get_first(void)

return ch;

}//獲取使用者輸入的計算值

float get_int(void)

}return input;

}//定義加法函式

float add(void)

//定義減法函式

float subtraction(void)

//定義乘法函式

float multiplication(void)

//定義除法函式

float division(void)

sum = i / j;

printf("%.2f / %.2f = %.2f\n", i, j, sum);

return sum;

}//定義開方函式

float extract(void)

sum = sqrt(i);

printf("%.2f的開方等於%.2f\n", i, sum);

return sum;

}//定義平方函式

float square(void)

//定義立方函式

float cube(void)

5樓:匿名使用者

#include

void main()

}c語言是一門通用計算機程式語言,應用廣泛。c語言的設計目標是提供一種能以簡易的方式編譯、處理低階儲存器、產生少量的機器碼以及不需要任何執行環境支援便能執行的程式語言。

儘管c語言提供了許多低階處理的功能,但仍然保持著良好跨平臺的特性,以一個標準規格寫出的c語言程式可在許多電腦平臺上進行編譯,甚至包含一些嵌入式處理器(微控制器或稱mcu)以及超級電腦等作業平臺。

二十世紀八十年代,為了避免各開發廠商用的c語言語法產生差異,由美國國家標準局為c語言制定了一套完整的美國國家標準語法,稱為ansi c,作為c語言最初的標準。[1]  目前2023年12月8日,國際標準化組織(iso)和國際電工委員會(iec)釋出的c11標準是c語言的第三個官方標準,也是c語言的最新標準,該標準更好的支援了漢字函式名和漢字識別符號,一定程度上實現了漢字程式設計。

一道簡單的c語言題目求解,一道簡單的c語言題目求解

include int main int main 在輸入時嚴格按照格式 來,字元與字元輸入之間用逗號隔開 include int main void 你可以自行新增一些細節問題,如做些非法性的判斷等!就可以了 include int main 加我q,我發給你後你採納,只能用你大號加。求解一道簡單...

用c語言設計課程資訊管理系統,用C語言設計一個課程資訊管理系統

include include include include using namespace std struct list typedef struct list node typedef node link 函式宣告 link create link head link search link...

用c語言計算矩陣加法和乘法,用c語言計算矩陣加法和乘法

謝謝你的回答,但是我看完你這個還有一個問題,你這裡k i都是 2,而j 3,那意思不不就是每組數都被捨去了 兩個數麼,還是說矩陣乘法就是這樣的規則,說實話我對矩陣乘法確實不瞭解了.求c語言矩陣加法和乘法 include include void memory int p,int m,int n 分配...