4 like 0 dislike

用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 程式設計(一)
Available when: Unlimited - Due to: Unlimited

retagged by | 199 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
Get it on Google Play Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:173.245.54.127
©2016-2021

Related questions

4 like 0 dislike
3 answers
[Normal] Coding (C) - asked Jan 3, 2018 in 程式設計(一)
Available when: Unlimited - Due to: Unlimited
| 342 views
4 like 0 dislike
1 answer
[Normal] Coding (C) - asked Jan 3, 2018 in 程式設計(一) by semicolon (5.2k points)
Available when: Unlimited - Due to: Unlimited
| 209 views
4 like 0 dislike
4 answers
[Normal] Coding (C) - asked Jan 3, 2018 in 程式設計(一) by thopd (12k points)
Available when: Unlimited - Due to: Unlimited
| 195 views
3 like 0 dislike
0 answers
[Normal] True/False - asked Feb 11, 2017 in Introduction to Computer Programming I (C) by The Contributor (20.9k points)
Available when: Unlimited - Due to: Unlimited
| 42 views
11,166 questions
132,624 answers
131,305 comments
3,823 users