8 like 0 dislike
12.4k views
若一個正整數的奇數位數字和與偶數位數字和兩者差的絕對值是11的倍數,則這個正整數就是11的倍數,否則就不是11的倍數。

請寫一個程式來判斷輸入的數是不是十一的倍數。

 

輸入說明:

會輸入一個正整數N,N不會超過1000位。

 

輸出說明:

如果輸入的數字是11的倍數就在螢幕上輸出YES,否則就輸出NO。

 

輸入範例:

11111111111111111111111111111111111111111111111111

 

輸出範例:

YES
[Exam] asked in 2017-1 程式設計(一)AD by (18k points)
ID: 36178 - Available when: 2017-12-08 18:30 - Due to: Unlimited
| 12.4k views

19 Answers

0 like 0 dislike
Hidden content!
#include<stdio.h>
int main()
{
** * ***** *** * **** *** *** i;
* * * * ** ** *** *** ** ** * a,b;
     int N[1000];
    
     scanf("%s", N);
     
* * * * ** * ** * ***** (i=0; i<=1000; i=i+2)
     {
** * **** * * * * ** * **** * * ****** * * *
* * * * ***** * * * **** ** * * ** * = a+N[i]; * * * ****** * ** ** * * * * ** *****
     }
     
* * **** * * * * * ** ** ** * ** (i=1; i<=1000; i=i+2)
* * * * * * ***** * * ***
*** ** * * **** ** * * * ****** *** ** ** * * * = b+N[i];
     }
     
* ********* *** *** * ** ** (a>b)
     {
** * * * * * **** * *** ***** * ** * ****** ((a-b)%11==0)
**** ** * * * *** **** * ******* * ***** * *
** ** ** ** **** * *** ** * ** ****** * * ****** * * * * * * *
** ** * ******* * ** * * * ** * * ****** ***
*** ** * *** * *** ** * * * ** * * * **** * *
** *** * * ** ** *** *** * * ** ** * *** * ***** * **
** *** ** * *** * *** *** * * *** ***** **** **** ** **** **** * ** * ** ***
******* ** ** ** ** **** **** ** * * ***** ** *
** * **** * **** **** * * ** * ****
** * * * * ** ** *** *** * * * * if (a<b)
     {
** * ** * * * ******* * *** * * ** **** * * ((b-a)%11==0)
* ** * * * * ***** * ** *** ** * * * * *** ***
******* *** *** *** *** *** * * *** * ** * ** * * ** * * ** *** * ** ** *
***** * * ** *** * * * *** ******** * * * * *
********* ** **** ** * * **** ******* * **** *** *** *
* **** ** * ***** *** * ** ***** * *** * ** *
** ** ** ***** ** * ** * * * * * ** * * * * *** * * ** *** * * * * * * ** * **** **
* * * ** ** * * ***** * **** * ***** * * * * *
** *** * * ** * ** * *** **
***** *** **** *** * ** ** * * * if (a=b)
** ** * ** * *** ***** ** * *
* * ** * * * *** * * * * * *** ** * ** * *** * * * * * * ** ** *** * * **
* * ** ** * ** ** * * ** ***
* ** *** ** * * ** ** * * ** * * *
** * ** * * * * * ** * * **** * * * **** ***** ** * *
** * ** ** * **** ** ** *** * 0;
* * ** ***** * * * *** * ** *
}
* *** * ** * ** * * * ***** * ** ****** * * *
answered by (202 points)
0 0
prog.c: In function 'main':
prog.c:8:11: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int *' [-Wformat=]
   scanf("%s", N);
           ^
prog.c:48:7: warning: implicit declaration of function 'system' [-Wimplicit-function-declaration]
       system("pause");
       ^~~~~~
0 0
prog.c: In function 'main':
prog.c:8:11: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int *' [-Wformat=]
   scanf("%s", N);
           ^
prog.c:48:7: warning: implicit declaration of function 'system' [-Wimplicit-function-declaration]
       system("pause");
       ^~~~~~
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main()
{
* * ***** * ** * *** *** long long n;
* ** * * * * ** * * **** ** ** ** *******
    {
*** ** ** * * * * *** ** * ** * ***** * *** *
* ** * * * **** * *** **** *** * * *** ***** ** * * **** ** * * * ** ** * *
* * ** ** ** ***

****** * ***** ** * 0;
}
answered by (114 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!
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
** *** * ** ** ** *** input[10000];
* ** ** * * **** ** ** * * ** ** ** *** **
    {
** **** * * ** *** *** *** * * ** *** * i,l=strlen(input),a=0,b=0;
** ** ** * * *** * *********** *** ** ********* *** **** ** ** ****
***** * * * * **** * ***** * * * **** * * * *** * * ** *
******* *** * ** ** * * *** * * * * * * * *** * * ****
*** * * * * * * * *** * **** ** **** * **** ** ** *** *
* *** ** ***** ** * **** **** * **** ****** * * * **
****** ** *********** *** * * ** * * * ****** * * *** ** * * * * ** ** * * ** * *
* ** * * * * ***** ** ** *** * * *** * * *** *** ***
** ** * ** * ** * *********** * ** * *** *** ** * ** ** ** ** ** ***** * ** ** ** * **** *
    }
** * ** * ****** ** * * ***** * 0;
}
answered by (30k points)
edited by
0 0
prog.c: In function 'main':
prog.c:7:19: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[10000]' [-Wformat=]
     while(scanf("%s",&input)!=EOF)
                   ^
prog.c:14:12: warning: implicit declaration of function 'abs' [-Wimplicit-function-declaration]
         if(abs(a-b)%11==0)
            ^~~
0 0
prog.c: In function 'main':
prog.c:14:12: warning: implicit declaration of function 'abs' [-Wimplicit-function-declaration]
         if(abs(a-b)%11==0)
            ^~~
0 0
prog.c: In function 'main':
prog.c:14:12: warning: implicit declaration of function 'abs' [-Wimplicit-function-declaration]
        ans=abs(a-b);
            ^~~
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 0
prog.c: In function 'main':
prog.c:13:12: warning: implicit declaration of function 'abs' [-Wimplicit-function-declaration]
         if(abs(a-b)%11==0)
            ^~~
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()
{
*** *** * ** * ** * * **** i,j,add=0,even=0;
*** * **** ** ** **** * * ** a[1000]={0};
* *** ** * *** * * * * *** * * * ***






* ** ** ** * * * * * * *** *** **
    {
* ** * *** ** * *** *** ** ** * *** * **** *
* * * * * **** * ** * *** ** * * * * ** * *
** *** * *** ** ** **** * ** ** **

* ** ********

* ** * ** *** *** *** * ** ** ** * ** * **** **
    {
* * ** * * * * ****** ********* * * * **** ** )
** ** ****** *** ** * * ** ** * * *** * ***
** ** * *** ** **** ** ***** * * ** * * ***

    }

* ** ** * *** **

* * *** ** * * **** * * ***** * *** * *** ** * * * * *

** ** ** * * * **** *** if((add-even)%11==0)
* ** *** ** ** * ***** ** * * * ******** * **** * * * *
** * * ** * ** **** **
** *** ** ** * * * ** * **** * ** *** * * * * ** **** * * ** ** *


* * * * ** *** **** *** 0;
}
answered by (174 points)
edited by
0 0
prog.c: In function 'main':
prog.c:10:13: error: 'i' undeclared (first use in this function)
     for(n=0;i=0;i<=a;i++) //\xe5\xa5\x87\xe4\xbd\x8d\xe6\x95\xb8\xe5\x81\xb6\xe4\xbd\x8d\xe6\x95\xb8\xe5\x88\xa4\xe6\x96\xb7,a<=10^999
             ^
prog.c:10:13: note: each undeclared identifier is reported only once for each function it appears in
prog.c:10:21: error: expected ')' before ';' token
     for(n=0;i=0;i<=a;i++) //\xe5\xa5\x87\xe4\xbd\x8d\xe6\x95\xb8\xe5\x81\xb6\xe4\xbd\x8d\xe6\x95\xb8\xe5\x88\xa4\xe6\x96\xb7,a<=10^999
                     ^
prog.c:12:18: error: invalid suffix "n" on integer constant
       if(c=a/10^(2n))
                  ^~
prog.c:17:22: error: expected ')' before ';' token
      for(n=0;i=0;i<=a;i++)
                      ^
prog.c:19:38: error: invalid suffix "n" on integer constant
                           if(d=a/10^(2n+1)
                                      ^~
prog.c:20:27: error: expected ')' before 'even'
                           even+=d;
                           ^~~~
prog.c:21:5: error: expected expression before '}' token
     }
     ^
prog.c:25:1: error: expected '}' before 'else'
 else
 ^~~~
prog.c: At top level:
prog.c:28:2: error: expected identifier or '(' before 'return'
  return 0;
  ^~~~~~
prog.c:29:1: error: expected identifier or '(' before '}' token
 }
 ^
0 0
prog.c: In function 'main':
prog.c:6:12: warning: zero-length gnu_printf format string [-Wformat-zero-length]
     printf("");
            ^~
prog.c:7:5: warning: 'gets' is deprecated [-Wdeprecated-declarations]
     gets(a);
     ^~~~
In file included from prog.c:1:0:
/usr/include/stdio.h:640:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
prog.c:14:16: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
     for(i=0;i<=strlen(a);i=i+2)
                ^~~~~~
prog.c:14:16: warning: incompatible implicit declaration of built-in function 'strlen'
prog.c:14:16: note: include '<string.h>' or provide a declaration of 'strlen'
prog.c:22:17: warning: incompatible implicit declaration of built-in function 'strlen'
      for(i=1;i<=strlen(a);i=i+2)
                 ^~~~~~
prog.c:22:17: note: include '<string.h>' or provide a declaration of 'strlen'
/tmp/ccEDkE9I.o: In function `main':
prog.c:(.text+0x51): warning: the `gets' function is dangerous and should not be used.
0 0
prog.c: In function 'main':
prog.c:6:12: warning: zero-length gnu_printf format string [-Wformat-zero-length]
     printf("");
            ^~
prog.c:7:5: warning: 'gets' is deprecated [-Wdeprecated-declarations]
     gets(a);
     ^~~~
In file included from prog.c:1:0:
/usr/include/stdio.h:640:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
prog.c:14:16: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
     for(i=0;i<=strlen(a);i=i+2)
                ^~~~~~
prog.c:14:16: warning: incompatible implicit declaration of built-in function 'strlen'
prog.c:14:16: note: include '<string.h>' or provide a declaration of 'strlen'
prog.c:22:17: warning: incompatible implicit declaration of built-in function 'strlen'
      for(i=1;i<=strlen(a);i=i+2)
                 ^~~~~~
prog.c:22:17: note: include '<string.h>' or provide a declaration of 'strlen'
/tmp/ccuq6Kb5.o: In function `main':
prog.c:(.text+0x51): warning: the `gets' function is dangerous and should not be used.
0 0
prog.c: In function 'main':
prog.c:6:13: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[1000]' [-Wformat=]
     scanf("%s",&a);
             ^
prog.c:13:16: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
     for(i=0;i<=strlen(a);i=i+2)
                ^~~~~~
prog.c:13:16: warning: incompatible implicit declaration of built-in function 'strlen'
prog.c:13:16: note: include '<string.h>' or provide a declaration of 'strlen'
prog.c:21:17: warning: incompatible implicit declaration of built-in function 'strlen'
      for(i=1;i<=strlen(a);i=i+2)
                 ^~~~~~
prog.c:21:17: note: include '<string.h>' or provide a declaration of 'strlen'
0 0
prog.c: In function 'main':
prog.c:7:13: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[1000]' [-Wformat=]
     scanf("%s",&a);
             ^
0 like 0 dislike
Hidden content!
#include<stdio.h>
int main(void)

{
** * * *** * * ***** * num[1000];
** * * *** * * i,a,b;
** * ** * * * *
* ** *** ** * *** * ** * * a number:");
* **** * * * * ***** = 0; i<1000; i+2)
* *** * * ** * *** ******
* * * ******** * * * += num[i];
* ** * ******* * * * * += num[i*2+1];
* * * * * * ** * ** **
* *** ** * * *
*** ***** **** ** * * * * * == 0)
* * ** ******** * * * * ** * * * * *
** ** * * * * * ** *
* * ** ****** **** ** * *
* ** ** *** ** * * ** * ***
* **** * * ***
***** * * * *** * * 0;
}
answered by (212 points)
0 0
prog.c:1:2: error: invalid preprocessing directive #inlude
 #inlude<stdio.h>
  ^~~~~~
prog.c: In function 'main':
prog.c:8:5: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
     printf("Enter a number:");
     ^~~~~~
prog.c:8:5: warning: incompatible implicit declaration of built-in function 'printf'
prog.c:8:5: note: include '<stdio.h>' or provide a declaration of 'printf'
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 like 0 dislike
Hidden content!
#include<stdio.h>
int main()
{
***** ** ***** *** ** *** x;
*** * ** * * ** ** *********** ** * enter a number\n");
** ** *** ********* ** * * *** * * ***** * * ** * **
*** ** ** * ** ** * * ***** *
*** * ** *** * * ** * * **** *** * ** * **** **** * ** ** **
*** ****** ****** * **** * *** ** *** ** * * *
* **** * * * ** * * ** * ***** * ** ** * ** * * * ** * ** * * * * ** * ***
    
**** * * * * *** * * * **
}
answered by (172 points)
1 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 like 0 dislike
Hidden content!
#include<stdio.h>

int main()
{   
** ** * * * *** ** * * a;
* * **** * * *** ** ** ******* * your number:");
* * * * *** *** ** * ** * *** *** * * ** ***
* * **** ** ** ** * % 11 == 0)
** * ** *** ** * ** ** ** **** * * **
*** **** * **** * ***
* * * * ** ******** ** * ** * * *** **
* ******* ** *** *** *
******** * * * *** ***** * * *** *** *
* *** * **** *** *** ** ** 0;
}
* * ** * ** * * *
answered by (164 points)
0 1
prog.c: In function 'main':
prog.c:13:5: warning: implicit declaration of function 'system' [-Wimplicit-function-declaration]
     system("pause");
     ^~~~~~
0 like 0 dislike
Hidden content!
#include<stdio.h>

int main(){
* *** * *** ** *
** * ** * ** ** * * * * num;
* ** **** ** * ***** **
**** ** *** ** * *** * * **** *** *****
* ***** **** * * * *** * *
    
** * ** * * ** ** * * * * ** ***
* * *** * *** * ** * *** * **
* * ** ** * * ** * ** *** *
*** * * * ***** * ** * * * * *** *

** * * * * * *
*** * ** **** ** *
}
answered by (192 points)
edited by
0 0
prog.c: In function 'main':
prog.c:8:13: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[1000]' [-Wformat=]
     scanf("%s",&ch);
             ^
0 0
prog.c: In function 'main':
prog.c:8:13: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[1000]' [-Wformat=]
     scanf("%s",&ch);
             ^
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Correct output
Case 3: Wrong output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Correct 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: Wrong output
Case 1: Wrong output
Case 2: Correct output
Case 3: Wrong output
0 0
prog.c: In function 'main':
prog.c:8:13: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[1000]' [-Wformat=]
     scanf("%s",&ch);
             ^
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Correct output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
* * *** ** ****** * *** *** in,a;
**** ********** ** *** * ***** * ** ** *
*** * *** ** * * * *
* * * ***** **** *** * * * *
* *** ****** ** * **
* ** *** * *** * * * * ** *
** *** *** * ** ** *** *** * * ** ** ******* ** ***** ***** *
* ** * * ** * ** * *********** ***
** *** * * **** * ** * if (a!=0){
***** * * *** * ** *** * ***** *** * * ** ******* *** * * ** *
**** *** ** * ** * * **** * ******* ** *
****** * *** ***** ** ** *
system("pause");
return 0;

}
answered by (185 points)
0 0
prog.c: In function 'main':
prog.c:6:14: warning: format '%ld' expects argument of type 'long int *', but argument 2 has type 'long int' [-Wformat=]
     scanf("%ld",in);
              ^
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main()
{
* * * * * ** ***** * j, k = 0, l = 0;
* * *** * ** * * ** ** str[10000] = {0};
* *** * * * ** * * * ** * **** * ***** str);
*** *** ** **** * * * ** * * = 0;j < strlen(str);j ++)
* ** ** * *** **** *****
****** * * ** **** * ** * * * * * * * % 2)
*** * *** * ** *** **** *** ** ***** * *
**** ** ** *** **** ** * ******** *********** *** * * *** * += str[j] - '0';
** * ** ***** ******* * ** *** * * ** ***** **
* * * ** * * **** ***** * * *** * ** * *
* ****** * * ** * * ** *** ****** * * *
** ** ** * * * * ** ** * ** ** ** * *** * * ***** ** **** * ** ** += str[j] - '0';
* * * * * * ***** ** **** * ** ** * * ***
* * * *** *****
** * ** * * * ** * - l) % 11 == 0)
*** * ** ******* * * *** ** **** ** *** * ** ******** *** ** *
* * ** ** * ** **
* ** ** ** ** * * *** **** * * ** ***** * * * * ********* *
}
answered by (18k points)
0 0
Case 0: Correct output
Case 1: Wrong output
Case 2: Correct output
Case 3: Wrong output
0 0
-----------Re-judge-----------
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:104.23.243.108
©2016-2026

Related questions

2 like 0 dislike
6 answers
[Normal] Coding (C) - asked Dec 20, 2017 in 2017-1 程式設計(一)AD by 楊修俊 (30k points)
ID: 38154 - Available when: Unlimited - Due to: Unlimited
| 2.8k views
2 like 0 dislike
8 answers
[Normal] Coding (C) - asked Dec 20, 2017 in 2017-1 程式設計(一)AD by 楊修俊 (30k points)
ID: 38155 - Available when: Unlimited - Due to: Unlimited
| 4.3k views
2 like 0 dislike
5 answers
[Normal] Essay (Open question) - asked Dec 20, 2017 in 2017-1 程式設計(一)AD by 楊修俊 (30k points)
ID: 38147 - Available when: Unlimited - Due to: Unlimited
| 1.7k views
12,783 questions
183,442 answers
172,219 comments
4,824 users