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 | 56 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 (154 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:172.69.62.148
©2016-2019

Related questions

4 like 0 dislike
3 answers
[Normal] Coding (C) - asked Jan 3, 2018 in 程式設計(一)
Available when: Unlimited - Due to: Unlimited
| 97 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
| 67 views
4 like 0 dislike
4 answers
[Normal] Coding (C) - asked Jan 3, 2018 in 程式設計(一) by thopd (11.3k points)
Available when: Unlimited - Due to: Unlimited
| 70 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
| 9 views
8,708 questions
69,918 answers
44,761 comments
1,828 users