国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊

C編程輔導(dǎo):CS101 Binary Arithmetic

2022-10-25 15:24 作者:拓端tecdat  | 我要投稿

原文鏈接:tecdat.cn/?p=29620

Requirement

In this Assignment, you should write a program that allows the user to perform simple arithmetic in binary. Upon starting, the program should tell the user that it is a binary math program, along with brief instructions on how to use the program.
The program should then enter a loop, where it gives a prompt, such as “input>”. Upon receiving input from the user, the program should process it, report the output result (or error), and loop back to the prompt. This should continue until the user gives the keyphrase to exit the program (keyphrase is your choice, good choices are “quit”, “end”, “exit”, etc.). For example:

Input> 101+1100 10001 Input> 111001-1010 101111 復(fù)制代碼

Analysis

Binary arithmetic, 也就是二進(jìn)制算法,是程序設(shè)計(jì)的基礎(chǔ)。本題需要實(shí)現(xiàn)一個(gè)可交互的程序,根據(jù)用戶輸入,實(shí)現(xiàn)二進(jìn)制算法,如二進(jìn)制加法、二進(jìn)制減法等。
本題難度不大,注意輸入的數(shù)據(jù)類型是char,需要拆分后轉(zhuǎn)換為int,以及keyphrase關(guān)鍵響應(yīng)符號(hào)的處理邏輯即可。

Tips

下面是處理用戶交互部分的實(shí)現(xiàn)

int main(int argc, char *argv[]) { ? char input[100]; ? char *keyphrase = "quit"; ? char *add = "+"; ? char *sub = "-"; ? char *mul = "*"; ? char *div = "/"; ? while (1) { ? ? printf("input> "); ? ? scanf("%s", input); ? ? if (strncmp(input, keyphrase, strlen(keyphrase)) == 0) { ? ? ? return 0; ? ? } ? ? if (strstr(input, add) != NULL) { ? ? ? binary_add(input); ? ? } ? ? if (strstr(input, sub) != NULL) { ? ? ? binary_sub(input); ? ? } ? ? if (strstr(input, mul) != NULL) { ? ? ? binary_mul(input); ? ? } ? ? if (strstr(input, div) != NULL) { ? ? ? binary_div(input); ? ? } ? } ? return 0; }


C編程輔導(dǎo):CS101 Binary Arithmetic的評(píng)論 (共 條)

分享到微博請遵守國家法律
临湘市| 务川| 临潭县| 敦煌市| 南雄市| 会泽县| 营山县| 东辽县| 商丘市| 凯里市| 聂荣县| 红桥区| 简阳市| 余姚市| 兴海县| 买车| 五指山市| 全南县| 安庆市| 泾源县| 白山市| 车致| 夏邑县| 铜鼓县| 六盘水市| 蒙城县| 墨脱县| 五莲县| 旬阳县| 永和县| 德安县| 聂荣县| 清水县| 隆昌县| 安西县| 朝阳区| 莆田市| 乌拉特后旗| 清水河县| 西林县| 陇南市|