4 like 0 dislike
1k views

用float定義2個數字,char定義運算符號(+,-,*,/)再使用switch判斷將四則運算做出

輸入為第1個數字(空格)運算符號(空格)第2個數字(列如:2 + 5)中間用空格隔開

input
5 + 6
output
11.000000
input
2 - 9
output
-7.000000
input
4 * -3
output
-12.000000
input
4 / 10
output
0.400000

 

[Normal] Coding (C) - asked in 程式設計(一)
ID: 40619 - Available when: Unlimited - Due to: Unlimited

retagged by | 1k views

3 Answers

0 like 0 dislike
Hidden content!
* ** ***** **
int main()
{
**** *** float a,c;
** * *   char b;
* ** ***** ****** * %c *********** ** * ** * *
** * ** * * {
* * ** * * * * * * * * ** ** * * * *
**** * * ** ***   int flag;
* * * * * **** * ** * *** **** **
* **** * ** * * ** ***** *** flag=1;
*** * * ** * * **** ***** * else **
* * *** * * *** *** * * * flag=2;
*** * ** * ** * else ****
*** * *** *** ** * * * ** ** ** flag=3;
**** *       else if(b=='-')
* ** **       * ** * flag=4;
** **   * * else
****** * *** ** * *** * ** * * break;
***** * ** * *** * * *** * **** ***** *
* * * * ** * * *** * ** ** *
**** * * ** * * *** {
*** * ** * ** * * * * case 1:
*** * ** * * * * * ** *** ** * * * **** * ** * *
** ** * * * * ** * *** * *** * break;
** * * ** * * * *** * * * case 2:
** * * * *** * ** ****** ** *** ** * *** ** **
** * * **** * *** * * * break;
*** ** * * * *** * * * *** case 3:
* * ** * * * *** ** ** ** * *** * * * * * * * *** ** * * * *
*** * * * ** * *** * * ** * break;
*** * *** * * * ** * case 4:
* * *** ** * **** *** * * ***** * * ** ***** * * ****
** * ** * *** ** **** ***** * break;
** * **** * * * * }
** *** ** **** }
* ** * *** * return 0;
}
answered by (100 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
Hidden content!
*
answered
0 0
prog.c:1:1: error: expected '=', ',', ';', 'asm' or '__attribute__' at end of input
 kjljkl
 ^~~~~~
0 like 0 dislike
Hidden content!
#include ** ** * ** *
#include ****** ** *
int main(int argc, char const *argv[])
{
* ** * float ***
* * ** **** char c;

* * ****** * ********** %c * ***** *** * * ** ** ** **
* *** ** ** *** **** ** * * ** switch(c)
** *** *** * ** *** * ** * {
** * * * * * * * *** case '+':
******* ***** * ** * * * ** *** * ** * * *** ans=a+b;
* ** * * * *** * ** * ** * **** * * * ** break;
**** * * ** * * * * * ***** *** case '*':
* * **** ** * * * * * *** * * * * * ** ans=a*b;
* * * * * ** * * *** * ** * * * ** * * ** break;
* ** ******* * ** *** * ** *** * case '-':
*** * * * * *** ** * ** * * * * ** * * ** * ans=a-b;
* * * *** * *** * * * ** *** * ** * ** break;
**** * ** ** ** *** * * ** *** ** case '/':
** ** * ** * * ***** ****** * * ***** ** * ans=a/b;
* * ** *** * * * * ** ** * *** * * * ** * break;
* ** ** * * ** *** *** *   * * * default:
***** * * * * ** **** * * ** ***** ** * * ** * * * *** ** ** * * ****
* ** * ** ** ** ** * * * * * * * break;
* *** ** * *** ** * * *** }

* *** * * ** ** * *** * * * * * ** * ** * * );

** * **** * * return 0;
}
answered by (114 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.71.254.248
©2016-2025

Related questions

4 like 0 dislike
3 answers
[Normal] Coding (C) - asked Jan 3, 2018 in 程式設計(一)
ID: 40624 - Available when: Unlimited - Due to: Unlimited
| 1.5k views
4 like 0 dislike
1 answer
[Normal] Coding (C) - asked Jan 3, 2018 in 程式設計(一) by semicolon (5.2k points)
ID: 40623 - Available when: Unlimited - Due to: Unlimited
| 815 views
4 like 0 dislike
4 answers
[Normal] Coding (C) - asked Jan 3, 2018 in 程式設計(一) by thopd (12.1k points)
ID: 40618 - Available when: Unlimited - Due to: Unlimited
| 1.3k views
4 like 0 dislike
2 answers
[Normal] Coding (C) - asked Jan 3, 2018 in 程式設計(一) by semicolon (5.2k points)
ID: 40622 - Available when: Unlimited - Due to: Unlimited
| 969 views
12,783 questions
183,442 answers
172,219 comments
4,824 users