2 喜歡 0 不喜歡
1.4k 瀏覽
小學一年級的數學

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

輸入說明:

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

運算元 運算子 運算元

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

輸出說明:

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

輸入範例:

1 +  2

輸出範例:

3
[練習] Coding (C) - 最新提問 分類:2017-1 程式設計(一)AD | 用戶: (18k 分)
ID: 31085 - 從幾時開始: 無限制 - 到幾時結束: 無限制

修改於 用戶: | 1.4k 瀏覽

23 個回答

0 喜歡 0 不喜歡
內容已隱藏
#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;
}
最新回答 用戶: (114 分)
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 喜歡 0 不喜歡
內容已隱藏
**** * * * ******* *
int main()
{
** ** *** int x,y,z;
** ** ** ** char a;
* *   * * ** * %c *** *** *** * * * ****** * ;
*** * ****
* * * *** * * * * * ** ***
* ** **   else
* * **   if(a=='+')
*** * ** * ** * ******* *** ***
* ** *   else
* * * * **** *
** * * * * ****** ** ** * ***
* * ** ** * * else
* * ** * *****
****** * **** **** * * * * *
* * * *
*** * * *** * ** ******** * ** **
* * ** * ***
* * *** * * ******* 0;
}
最新回答 用戶: (172 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 喜歡 0 不喜歡
內容已隱藏
** * ** * * *
int main()
{
 int a,c,x;

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

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

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

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


* ** ** * * * * * * ***
 return 0;
}
最新回答 用戶: (236 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 喜歡 0 不喜歡
內容已隱藏
#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;
}
最新回答 用戶: (212 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 喜歡 0 不喜歡
內容已隱藏
#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;
}
最新回答 用戶: (194 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 喜歡 0 不喜歡
內容已隱藏
* * **** ******
int main()
* * * ***
** *** * * char a,b,c;
* ***   int * *
* * * *
  * ** ** * * *** %c * **** **** * * ** ***** * *
*** * ** * * * ***
***** ** * if(b == '+')
** *** * *** {
** *   *** ** *** * *** ** **** **
* *   ** *** * ** * ** ** * * *
**   ** ** ***** * * * * * * ** **
***** * * * * * ***
** * ** * * ***** * **** *** ** * ** ** ** * ****
** ** ** ** }
* * * * else if(b == '-')
** * ** ** {
* * *** * *** * * **** **** * *****
* ** * **   * ** * * ** ****** * * *
**   **** * * *** *** ***
* *      
        * * ** * ** * *** * ***
* * **   }
****   else if(b == '*')
* *** * * {
** * ** * * * * * * *** ***** * *** **
*** * * ** * ******* * ** ** * ** * *** * *
* * ***** * ****** **** * ***** * * * **
* * ** * *** **
* **** * * * ** * ** ** * ***** ** ****
* * ***** }
* * ** * else if(b == '/')
** ** * {
** * * *** ** * ****** ****** *********
* * * * * * * ** * ** ** ****** ** *
** * ** ** * *** * *** **** ** *** ** **
** * *** * * * * ****
** ** ** * * **   ** *** * ** ***
* * ** * }
** *** ** else
** ** * * {
* *** * * *** ** * ** ***** * * * * **** *
** * *** }
** * *   return 0;
* **** *
}
最新回答 用戶: (202 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 喜歡 0 不喜歡
內容已隱藏
******* * ***** *

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

* * ** **
*** * ** ch1 = *** **
* ** * * ch2 = ** *
** * * * * ch3 = *******
* * * * ***
** * * * * if( ch2 == 43 )
*** ** * *** * * ** * ** ** ***** ** **
****** **** * else if( ch2 == 42)
* ** ***** * ** * * *** * * * ** * *
** ** * * * else if( ch2 ==45)
*** ** ** * ** * * * * * **
* ** * *** else if( ch2 == 47)
* * * * ** * * *** * * ****** ** **** *** * *
*** * **** *
* *** ***
** ** * * ** * 0;
* * ***
最新回答 用戶: (160 分)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 喜歡 0 不喜歡
內容已隱藏
**** * * ******

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

** * * ***** ** ** ***** * * ** * **
* * * ch1 = ***
** ** * *** ch2 = * *
*** * * **** ch3 = * *
* * * ** *
* * * * if( ch2 == 43 )
* * * * * * * * * ** * * **
* * * *** * else if( ch2 == 42)
* * ** * ** ** * * ** ** * ** * ** ** * ***
** else if( ch2 ==45)
*** * * ** * ** * * * ******
**** ** * * * else if( ch2 == 47)
*** * * **** ** ** ** **** * * **** ** ****
* ** * * **
*** *****
*** *** * return 0;
* * *
最新回答 用戶: (160 分)
0 1
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 喜歡 0 不喜歡
內容已隱藏
#include<stdio.h>
#include <stdlib.h>
int main()
{
** * * * ** * * * * a,b,c;
*** ** * ** * ** *** ** ** * %c * * * * ** ** ** ** * * * *
*** * *** * **** ** * * d=a-'0';
** ** * * * * * *** e=c-'0';
** * ** * ** *** ** * * * * *
*** ** ***** * * **
* * **** ** ** * ***** * *** *** * ** * * * ***** *** *** **** **
    }
* **** *** * * if(b=='-')
*** ** *** * ******* * ** * ***** * ** ** * **** * *
* * * * * ** * * ** if(b=='*')
* ** ******** * *** ** * * * ** * ** ** ******* **** * *
*** * * ** ** ** * **
** **** * * * ** *** ** *** * *** ** * ***** ***** * ** * **
** * *** ** * * **** * 0;
}
最新回答 用戶: (100 分)
1 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 喜歡 0 不喜歡
內容已隱藏
#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;
}
最新回答 用戶: (138 分)
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.70.178.189
©2016-2024

相關問題

2 喜歡 0 不喜歡
29 回答
[練習] Coding (C) - 最新提問 11月 9, 2017 分類:2017-1 程式設計(一)AD | 用戶: Shun-Po (18k 分)
ID: 31094 - 從幾時開始: 無限制 - 到幾時結束: 無限制
| 1.7k 瀏覽
2 喜歡 0 不喜歡
31 回答
[練習] Coding (C) - 最新提問 11月 9, 2017 分類:2017-1 程式設計(一)AD | 用戶: Shun-Po (18k 分)
ID: 31088 - 從幾時開始: 無限制 - 到幾時結束: 無限制
| 1.8k 瀏覽
3 喜歡 0 不喜歡
9 回答
[練習] 對錯二選一 - 最新提問 11月 16, 2017 分類:2017-1 程式設計(一)AD | 用戶: 楊修俊 (30k 分)
ID: 33763 - 從幾時開始: 2017-11-16 14:00 - 到幾時結束: 2017-11-16 14:30
| 274 瀏覽
3 喜歡 0 不喜歡
9 回答
[練習] 對錯二選一 - 最新提問 11月 16, 2017 分類:2017-1 程式設計(一)AD | 用戶: 楊修俊 (30k 分)
ID: 33764 - 從幾時開始: 2017-11-16 14:00 - 到幾時結束: 2017-11-16 14:30
| 342 瀏覽
1 喜歡 0 不喜歡
0 回答
[Resource] 最新提問 1月 4, 2018 分類:2017-1 程式設計(一)AD | 用戶: 楊修俊 (30k 分)
ID: 40762 - 從幾時開始: 無限制 - 到幾時結束: 無限制
| 26 瀏覽
12,783 問題
183,443 回答
172,219 留言
4,824 用戶