2 like 0 dislike
5.1k views
小學一年級的數學

剛開始學習數學的時候,我們都是從個位數的加減乘除開始學習的,請寫一個程式,教你的程式學會個位數的加減乘除。

輸入說明:

程式會輸入三個字元,代表一個算式,會用下面的樣式呈現

運算元 運算子 運算元

其間會用單一個空白隔開,運算元是一個個位數的數子,運算子可能是+-*/中的任何一個。

輸出說明:

請輸出輸入算式的結果到整數位數

輸入範例:

1 +  2

輸出範例:

3
[Exercise] Coding (C) - asked in 2017-1 程式設計(一)AD by (18k points)
ID: 31085 - Available when: Unlimited - Due to: Unlimited

edited by | 5.1k views

23 Answers

0 like 0 dislike
Hidden content!
#include * ** ** * ***
#include * **** ** * *
int main(int argc, char const *argv[])
{
* ** * *** int * ** **
* ** * ** 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
prog.c:1:1: error: expected identifier or '(' before numeric constant
 4#include <stdio.h>
 ^
prog.c:1:2: error: stray '#' in program
 4#include <stdio.h>
  ^
In file included from prog.c:2:0:
/usr/include/string.h:43:8: error: unknown type name 'size_t'
        size_t __n) __THROW __nonnull ((1, 2));
        ^~~~~~
/usr/include/string.h:46:56: error: unknown type name 'size_t'
 extern void *memmove (void *__dest, const void *__src, size_t __n)
                                                        ^~~~~~
/usr/include/string.h:62:42: error: unknown type name 'size_t'
 extern void *memset (void *__s, int __c, size_t __n) __THROW __nonnull ((1));
                                          ^~~~~~
/usr/include/string.h:65:56: error: unknown type name 'size_t'
 extern int memcmp (const void *__s1, const void *__s2, size_t __n)
                                                        ^~~~~~
/usr/include/string.h:92:48: error: unknown type name 'size_t'
 extern void *memchr (const void *__s, int __c, size_t __n)
                                                ^~~~~~
/usr/include/string.h:129:39: error: unknown type name 'size_t'
         const char *__restrict __src, size_t __n)
                                       ^~~~~~
/usr/include/string.h:137:9: error: unknown type name 'size_t'
         size_t __n) __THROW __nonnull ((1, 2));
         ^~~~~~
/usr/include/string.h:143:57: error: unknown type name 'size_t'
 extern int strncmp (const char *__s1, const char *__s2, size_t __n)
                                                         ^~~~~~
/usr/include/string.h:150:8: error: unknown type name 'size_t'
 extern size_t strxfrm (char *__restrict __dest,
        ^~~~~~
/usr/include/string.h:151:40: error: unknown type name 'size_t'
          const char *__restrict __src, size_t __n)
                                        ^~~~~~
/usr/include/string.h:280:8: error: unknown type name 'size_t'
 extern size_t strcspn (const char *__s, const char *__reject)
        ^~~~~~
/usr/include/string.h:284:8: error: unknown type name 'size_t'
 extern size_t strspn (const char *__s, const char *__accept)
        ^~~~~~
/usr/include/string.h:394:8: error: unknown type name 'size_t'
 extern size_t strlen (const char *__s)
        ^~~~~~
/usr/include/string.h:446:33: error: unknown type name 'size_t'
 extern void __bzero (void *__s, size_t __n) __THROW __nonnull ((1));
                                 ^~~~~~
prog.c: In function 'main':
prog.c:8:2: warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
  scanf("%d %c %d",&a,&c,&b);
  ^~~~~
prog.c:8:2: warning: incompatible implicit declaration of built-in function 'scanf'
prog.c:8:2: note: include '<stdio.h>' or provide a declaration of 'scanf'
prog.c:24:5: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
     printf("Wrong input\n");
     ^~~~~~
prog.c:24:5: warning: incompatible implicit declaration of built-in function 'printf'
prog.c:24:5: note: include '<stdio.h>' or provide a declaration of 'printf'
prog.c:28:3: warning: incompatible implicit declaration of built-in function 'printf'
   printf("%d",ans );
   ^~~~~~
prog.c:28:3: note: include '<stdio.h>' or provide a declaration of 'printf'
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
Hidden content!
* ** * ***
int main()
{
* *** int x,y,z;
* ** ** char a;
*   ******* ** %c **** *** * ** * **** * *** ;
** * ** *** *
*** * * **** * *********** ** *
* ***   else
* ****   if(a=='+')
* ** *** *** ** ** *** *** *
****   else
* * * ** * * ****
*** * * ** ** * * ** *
*** * *** else
*** * * * ***** ****
** * ** * * * ***** * * ** ** *** ***
* *** ** *
* * ** ** **** * ** * *
* * **** *
* * * ** * ** * * ***** ** 0;
}
answered by (172 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
Hidden content!
****** ** **
int main()
{
 int a,c,x;

 char b;
******* *** **** %c ** ** ** ** * ** **** ** ***

if(b=='*')
* * ** * ** ** ** * ***
*** *** ** **** * ** if(b=='-')
* ** ** * * * ** * ********* ** **** *** ** ** *

** * ** ** *** * ** ** * ** ** * * * if(b=='+')
*** ** * * ** * ***** ****** *** * ***** ** ** * ** * ****** *

* **** ** * *** * * ** * * * * * * if(b=='/')
** * * ** * *** **** * **** ** * * ** ***** ** ** ** ** * **** ** * * *** * * *


***** ** * * * ***** *
 return 0;
}
answered by (236 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
int main(){
    int a,b;
**** ** * * * ** ** * * * * c;
** * ** *** *** ** ** %c * *** **** **** * *** **
*** *** *** * ** * * ** ** ** *
* ***** * * * ** * ** * * * * *** * * ** *** 0;
* ** ** * *** * * ** *** ** * * * *
**** * ***** *** *** * *** ** ** * ** *** * ** 0;
** ** ** **** * **
** * *** ** * ** ** * * ** ** * ** * ** *** * ** *
** * ***** **** **** if(c=='-')
*** ** * * * * ** * * ******** * *** * ** * * * ** * **** * *
    else if(c=='*')
** ** ** *** * * *** * * *** * ** *** ** * * * ** *
    else if(c=='/')
* * * * ***** * * **** * * ** * * * *** ** * * *** * ** *
* ** ** * * * * *** *
* ** * * * * * * * * *** * * 0;
* * *** **** * * * ** ****** 0;
}
answered by (212 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
int main(){
    int a,b;
* ** **** *** ** * ** *** c;
** ** ** ****** * ** ** * %c ** ** ** * ** * *
* *** * ** * ** ** ** ** ******** *
** * * ** * * ** * ** * ** * * *** ********** * 0;
* **** ** *** * * * * * ******* ** * ***
** *** ** * ** **** *** * ** ** ** ******** **** 0;
** ** ** ** * ** *** ** * ***
* *** ******** * * ****** ** ** *** **** * * * * * ** *
* **** ** * * ** ** if(c=='-')
* * ****** * ** ** * ** * ** ***** ** * ****** **** **** ** ** *
    else if(c=='*')
* * *** * * * * ** * * ***** ** **** * ** * ** * ****
    else if(c=='/')
** *** *** ** * ** ** ** * * *** ** * ** ** *** *** **
**** * * * * * ** * *
*** * * * * * * * * *** *** *** 0;
** * ***** * * * * 0;
}
answered by (194 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
Hidden content!
** * *** ** ** ***
int main()
** * *
* ** * * * char a,b,c;
*   int * * * **
**** * * **
  * * *** * * %c * ** *** ***** * ***
*** * ** *
* * ** * if(b == '+')
* * * * {
* ****   ** ** ** * ** ******* * **
* *   * * ** * ** * * ** *** *
** ***   * ** * * ** **** * * * * **
* ** ** * * ** **
* *** ** * **** * *** ****** * *** * **
** *** * ***** }
** * ** else if(b == '-')
*** ** *** ** {
* * **** * * * **** *** **** ** ** **
** **   **** ** * * * * ** * * **
* **   ** * ** * * * ** **** ** *
* * *      
        * * *** *****
* ****   }
***   else if(b == '*')
* * ** ** {
*** * * *** * *** ** * * ** ** * * * *
* ** ** * * * * * ***** *
*** ** *** ** * * * * *** * * *****
* * ** * * **
**** * * ** * * *** * ** * * *** ** *** **
**** * ** ** }
* ** * *** ** * ** else if(b == '/')
***** ** * ** {
* * * * * ** ** * **** * ** * * * * *** *
* * * * * ***** * * **** **** * *
* ** * * * ******* * * * ** * *** * **
* *** *** ** *** *
*** ** * * * *   ** * * * * ** **
*** ***** }
* **** ** * else
** * ** * {
* ** * * *** * ** * **** * * ******* * * * * * * ***
* * *** * * ** }
* * *   return 0;
* * *****
}
answered by (202 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
Hidden content!
* **** **** ****

int * *** **
{
***** * char * * * *

* ** ***
* **** ** ** * ch1 = * *****
* * ** * ch2 = * **
* **** * * * ch3 = * ***
** * * ** *
* ** * * if( ch2 == 43 )
**** * ** ** * * * ** **** * ** **
* * * *** else if( ch2 == 42)
** *** * * ** * * * * ** * * ** *
* * * * ** *** * else if( ch2 ==45)
* ** * * ** ** *** ** *** * * ** *
*** * * *** else if( ch2 == 47)
* ** * * * * * * *** * *** * * ** * *
* * ** * **
* ** *
** ** ** *** ** * 0;
* ***** *
answered by (160 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
** ****** * * **** *

int *** * * *
{
*** *** * *** char ** *

* ** ** ***** * * **** * * * ** * **
**** *** ch1 = *
** * ** * ** ch2 = * **
*** * * ch3 = * *
* * **
**** if( ch2 == 43 )
* **** ** * * * **** * ** ** ** **
* *** ** ** else if( ch2 == 42)
* * * ** * * * ** * ***** *** * * ** * **** *
* ** ** ** else if( ch2 ==45)
** * * *** *** * * * ** ** * * **
*** * * ** else if( ch2 == 47)
* * *** ** ** * ** * *** * * * * * **
* ** *** *
* *** ** * *
* ** return 0;
*****
answered by (160 points)
0 1
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include <stdlib.h>
int main()
{
* * ** ** * *** ** * ** a,b,c;
* ** * * **** ** ******* ** %c ** *** * * **** *** **
**** ** *** ** * ****** * d=a-'0';
* ** *** *** * * *** * e=c-'0';
** ** *** *** * * * ** *
*** * * *** ** * *
***** **** *** ** ** ** ** ** * ***** * ** ** * * * * ** * **** * ***
    }
* ** *** * * ** *** if(b=='-')
** **** **** ** * * * * * * * ** ** *** ** ** **** *** *
* *** ***** * * * * ** * if(b=='*')
* * * * * *** ** **** * ***** * * * * * * * ** * * * * ** * ****
* * ** **** ** *
** * ** ** *** **** ** * ****** *** ** **** * ** ***** ***** * ** ** *
*** **** * * * **** ** * 0;
}
answered by (100 points)
1 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>

int main(void)
{
*** **** * ***** * a, c;
* ** * ** ** **** * ** * * * b;
*** ** * * ** ***** ** ** * * ** * %c %d", &a, &b, &c)
* *** **** *** *** *** * == '+')
* **** * * **** * * * *** ** ** ** * ** *** * * a+c);
****** * * **** * ***** ** * **** if(b == '-')
* ***** *** * **** * * * * * * ** * ** ****** *** * * a-c);
* ****** * * * * * ** ** if(b == '*')
** * ** ** * * ** * * * * * ** * ** **** ** *** a*c);
* * **** ** * * * ** *** if(b == '/')
** * * ********** ** ** * ****** ** * *** * * ** ** * a/c);
* ** **** * ** *** * *
* * * ** *** *****
* * * *** 0;
}
answered by (138 points)
0 0
prog.c: In function 'main':
prog.c:8:5: error: expected ';' before 'if'
     if(b == '+')
     ^~
prog.c:10:5: error: 'else' without a previous 'if'
     else if(b == '-')
     ^~~~
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.59.110
©2016-2025

Related questions

2 like 0 dislike
29 answers
[Exercise] Coding (C) - asked Nov 9, 2017 in 2017-1 程式設計(一)AD by Shun-Po (18k points)
ID: 31094 - Available when: Unlimited - Due to: Unlimited
| 7.4k views
2 like 0 dislike
31 answers
[Exercise] Coding (C) - asked Nov 9, 2017 in 2017-1 程式設計(一)AD by Shun-Po (18k points)
ID: 31088 - Available when: Unlimited - Due to: Unlimited
| 7.8k views
3 like 0 dislike
9 answers
[Exercise] True/False - asked Nov 16, 2017 in 2017-1 程式設計(一)AD by 楊修俊 (30k points)
ID: 33763 - Available when: 2017-11-16 14:00 - Due to: 2017-11-16 14:30
| 1.1k views
3 like 0 dislike
9 answers
[Exercise] True/False - asked Nov 16, 2017 in 2017-1 程式設計(一)AD by 楊修俊 (30k points)
ID: 33764 - Available when: 2017-11-16 14:00 - Due to: 2017-11-16 14:30
| 1.2k views
1 like 0 dislike
0 answers
[Resource] asked Jan 4, 2018 in 2017-1 程式設計(一)AD by 楊修俊 (30k points)
ID: 40762 - Available when: Unlimited - Due to: Unlimited
| 26 views
12,783 questions
183,442 answers
172,219 comments
4,824 users