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

2021-07-30 12:59:28 字數 5530 閱讀 9874

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()

printf("%f%c%f=%f\n",x,c,y,z);

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

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

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

簡單的C語言題目。用的軟體是visual c

程式的問題很多,我不知掉你具體想做什麼,以下是我修改過的 用一個陣列來存放輸入的值 1 輸入這個陣列,類似初始化這個陣列 2 輸出這個陣列 3 求這個陣列的最小值 int shuzu2 10 void choose1 void choose2 int choose3 return min void ...

c語言習簡單的題目,一道 c語言題目 謝謝

汗啦。這個相當於 for i 1 i 4 i for j 1 j 5 j m 一共迴圈了4 5 20次。所以m等於20 這樣寫你就明白了吧?當然如果你這裡的i,j有其他用法可以那樣寫。如果沒有的話,不建議。汗。樓主你自己數一下就知道了麼 i 1,i 5,i 9,i 13.然後跳出j 3,j 7,j ...

C語言程式設計迴圈結構的題目,C語言程式設計 要求用迴圈結構程式設計

include void main 計算x有幾位存放在n中 xx x k 1 for i 0 i include void xs int a int main void xs int a for j 0 j 這個看情況了,其實不用陣列也是能寫出來的,可以用除10的方法得到數字的個位數。例如12345...