8 thích 0 k thích
1.3k đã xem
若一個正整數的奇數位數字和與偶數位數字和兩者差的絕對值是11的倍數,則這個正整數就是11的倍數,否則就不是11的倍數。

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

 

輸入說明:

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

 

輸出說明:

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

 

輸入範例:

11111111111111111111111111111111111111111111111111

 

輸出範例:

YES
[Exam] đã hỏi trong 2017-1 程式設計(一)AD bởi (18k điểm)
ID: 36178 - Xem được từ: 2017-12-08 18:30 - Hiệu lực đến: Không giới hạn
| 1.3k đã xem

19 Trả lời

0 thích 0 k thích
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;
* * ****** ** * ** ** * * * ** ** *
}
* ** *** * * *** * * * ** ** ** * ** *** ***
trả lời bởi (202 điểm)
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 thích 0 k thích
Hidden content!
#include <stdio.h>

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

* * * * ** * * * * * 0;
}
trả lời bởi (114 điểm)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 thích 0 k thích
Hidden content!
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
*** * * ** * ** * input[10000];
*** * *** * ** * ** ***** ** * * ** * ** * * * * *
    {
*** *** * * ** **** * *** * *** *** * *** i,l=strlen(input),a=0,b=0;
***** ** ****** * * * ***** ** ** *** ****** * ** ** * *** ** *
** ** ** ** * * * * ** * *** * ** ****** ** * *** * * ** *
* **** * * ** ** ** * *** ** ********* * * *** * * *
* * **** * **** * ** ** *** * * **** ***** ***
* **** * ** * * *** * * * * * *** * * * ** * * *
***** * * ** * * ** *** ** * * ** ** * * * **** ** ** ********* ** ** ** **** **
* ** ** *** * ** **** * ** ***** * * *
* * * * * ** *** ** * * * * ***** ******* * * * ** * ** * * * * * ********** *
    }
** * * ****** * **** * 0;
}
trả lời bởi (30k điểm)
đã sửa bởi
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 thích 0 k thích
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;
}
trả lời bởi (174 điểm)
đã sửa bởi
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 thích 0 k thích
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;
}
trả lời bởi (212 điểm)
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 thích 0 k thích
Hidden content!
#include<stdio.h>
int main()
{
* ** ** * ** * ** x;
****** * * ** *** * ** ***** * * enter a number\n");
* ****** * * ** *** * *** * ** *
* * ** * ** ******* ** ** * ** *
* * * * * * * * ** * ** ** ****** * *** * * **** * * *
* * * **** *** ** * * * * ** ** * ** ** * * * * *
* **** ** * **** * ** ** ***** * ** * * **** ** * *** *** *** * * *** * *
    
** ** * *** * ***
}
trả lời bởi (172 điểm)
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 thích 0 k thích
Hidden content!
#include<stdio.h>

int main()
{   
* **** ** * ** ** ***** a;
** ***** *** * * * ** * * ** *** your number:");
* **** ****** ** * * * *** ** * ** ******* * ** *
* ** *** ****** * ** *** * * % 11 == 0)
* ** * * *** * * **** * * ****** * * * **
***** ** ** * ***** **
** ** * ** ** * * *** * * * * * *
**** *** *** * *** *** *
* ** *** * * ** *** ******** *** ** ***** **
*** ** *** * ** ** *** ***** 0;
}
* * * * *** ** * *** *
trả lời bởi (164 điểm)
0 1
prog.c: In function 'main':
prog.c:13:5: warning: implicit declaration of function 'system' [-Wimplicit-function-declaration]
     system("pause");
     ^~~~~~
0 thích 0 k thích
Hidden content!
#include<stdio.h>

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

* *** * * ** ** ***
* * *** *
}
trả lời bởi (192 điểm)
đã sửa bởi
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 thích 0 k thích
Hidden content!
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
*** ** * * * ** ** *** **** in,a;
* *** * * ** * * ** *** * *** *
* * * ** ** ******
** ** * **** ***** * *
****** * * ** * *
* **** *** * ** ** * **** ***
*** * * *** ** ** * ** * ** * * *** ** * * * * *
* ** * *** ** **** * ** * ** * ** *
* * **** ** * ** if (a!=0){
* *** *** * * *** *** **** ** ** **** ** **** * *** *** ** **** * **
* * **** **** *** * ** * *** ** * * * * * * **
** * * ********* **
system("pause");
return 0;

}
trả lời bởi (185 điểm)
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 thích 0 k thích
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)
* ******** *** ** ****** **** ** * *** * * * * ***** * ** * ***
** * * * ********** * **
* ** ** ***** **** ** ** ** ** * * * **** * ** * *
}
trả lời bởi (18k điểm)
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:172.70.130.127
©2016-2024

Những câu hỏi liên quan

2 thích 0 k thích
6 trả lời
[Normal] Coding (C) - đã hỏi ngày 20 tháng 12 năm 2017 trong 2017-1 程式設計(一)AD bởi 楊修俊 (30k điểm)
ID: 38154 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 323 đã xem
2 thích 0 k thích
8 trả lời
[Normal] Coding (C) - đã hỏi ngày 20 tháng 12 năm 2017 trong 2017-1 程式設計(一)AD bởi 楊修俊 (30k điểm)
ID: 38155 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 522 đã xem
2 thích 0 k thích
5 trả lời
[Normal] Essay (Open question) - đã hỏi ngày 20 tháng 12 năm 2017 trong 2017-1 程式設計(一)AD bởi 楊修俊 (30k điểm)
ID: 38147 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 237 đã xem
12,783 câu hỏi
183,443 trả lời
172,219 bình luận
4,824 thành viên