0 like 0 dislike
5.8k views

Write a program that reads integers and stores them in an array. Then, the program should rotate the elements one place to the right. For example, if the array were 1, -9, 5, 3, the rotated array would be 3, 1, -9, 5.

寫一個程式 輸入整數放在陣列裡。將陣列裡面的元素向右旋轉一次

Example input 1: First number is the element of array to input, then the list of numbers

4
1 -9 5 3

Example output 1:

3 1 -9 5

 

Example input 2:

5
2 7 9 3 12

Example output 2:

12 2 7 9 3

Please remember, you may correct the cases, but your code always be revised!

[Exercise] Coding (C) - asked in Chapter 8: Arrays by (5.2k points)
ID: 34913 - Available when: 2017-11-30 18:00 - Due to: Unlimited

edited by | 5.8k views

56 Answers

0 like 0 dislike
Hidden content!
* *** ** *** **
int a[100];
int b[100];
int ***
int main(){
* ** ****** ** * *
* * ** ** *** ****
** * *** * * * *** *
** * ** **
** *
** *


**** * ** ** ** * *
for ****** * ** *
** *** ** **** *
}
answered by (-336 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 a[100];
int b[100];
int * *
int main(){
** * * *** ** * * ** *
* ** * * ** *
*** * * *** * * * ** *
* * * *
***
* * * *
for ** * * *** *
*** * *** * *** * **
}
answered by (-336 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 *** * ** * *

int main()
{
** **** * ** * * * * * i,N,cnt=0;
*** ** *** ****** ** * ** ***** &N);
***** *** * ** * * ***** * a[N];
* * ** * ** * ***** = 0; i < N; i++)
******* * ** ** * * * ** * ** ** * * ** * **** * * * ******* * * *
* * * ***** * *** * *** * * ",a[N-1]);

*** * * *** * * * = 0; i<N-1; i++){

** **** * * * * (i==N-2)
********* **** ***** * * * * *** * * * ** * ** ** ** * * * **** *
* ***** ** * * * ******* * * *
** * **** *** *** *** * * * * * ****** *** *** *** ",a[i]);
* * * ** * ** ****
**** **** * * *** * * * 0;
}
answered by (-127 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 * ** ** * *
#include * * ** ** *** *

int main()
{
* * * ** * * * * **** ** i,N,cnt=0;
* *** **** ** * * * * ** * * ** ** ** * &N);
** * ***** ** ** ** * ** ** a[N];
*** *** ** * * * ** ** * = 0; i < N; i++)
* ** * * * * * * **** * * * * * * ** ***** * * ** * ***
**** ***** * **** ** ****** ** * ",a[N-1]);

** * *** ** **** ** ** * = 0; i<N-1; i++){
*** ********* * * * * * * * * * * * * ** *** * *** * * ",a[i]);
*** ****** * ** * * * ** *** (cnt==N-2)
*** ***** * * * ** * * ** * * * * *** ***** *** * * ****** *** **
**** * **** * ***** ****
* * * * ** * * ** ** **** ** 0;
}
answered by (-127 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 ** ** * **
#include *** ***** *

int main()
{
* * ** * * ** * ** ********* i,N,cnt=0;
** ***** * ************* ** ** ********* * * &N);
* * * * * * ** * *** a[N];
*** * ** * * ** * ** = 0; i < N; i++)
* * **** * * * * *** * ***** * * * ** ***** *** * * *
* ****** * ** * * * ** * * * * * ",a[N-1]);

**** ** *** * ** ** * ** * * = 0; i<N-1; i++)
* * * ** ** * ***** ** ** * **** **** ****** * * * * ",a[i]);
*** * ** * *** * * **** (cnt==N-1)
*** *** ** * *** * * * ** * **** * * * * ** * **** * * ** *
* * * **** ** * 0;
}
answered by (-127 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 main()
{
* ** ***** * **** i,N,cnt=0;
***** * ** * ** * * * * &N);
*** * * ** * *** * * a[N];
** **** * * * *** = 0; i < N; i++)
**** ** * * * *** * *** * ** **** ** *** *** ** * * ** *** ** * *** ** *
*** ** * ** ** ** * **** * * ",a[N-1]);

*** *** *** * * *** * * * * = 0; i<N-1; i++)
** * * **** * * * *** * *** * ** ** ** ** * * * *** * ",a[i]);
*** * *** * **** * * **** ** (cnt==N-1)
* ** *** **** ** *** * *** * ** ******** * * * ** **** ** *
** *** *** * *** *** 0;
}
answered by (-127 points)
0 0
prog.c: In function 'main':
prog.c:4:5: warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
     scanf("%d", &N);
     ^~~~~
prog.c:4:5: warning: incompatible implicit declaration of built-in function 'scanf'
prog.c:4:5: note: include '<stdio.h>' or provide a declaration of 'scanf'
prog.c:8:5: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
     printf("%d ",a[N-1]);
     ^~~~~~
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 like 0 dislike
Hidden content!
#include <stdio.h>

int main()
{
** * * * ***** n,N,digit;
* * * **** *** ** * ** * * ** *** * * * *
** * * * * numbers[digit];

** * *** * * ** * * * (n=0;n<digit;n++)
** * * ** * ***** ** *
* * *** * * * ***** * ** **** * *** * * *** * *** * *** **
* ** * **** * *
* * * ** * ******* * * ******** ** * ** ** * *
* ** * * * ** * *** (n=0;n<digit-1;n++)
** * * ** ** *** *
** **** ** * * * * ** ** * *** ** ** * * **** * ** %d",numbers[n]);
***** * * *** * * *
* * *** *** * * ** * * ** 0;
}
answered by (-249 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>

int main() {
**** * * * ** a[99],i,k,j,t,z,count=0;
***** * **** * * * * ** *** * **** * {
* * ** ** ** *** ** *** ** * *** *** * * * ***
** *** *** ** ** * *

* ** *** * ** * ** ** * ** * * &i);
*** * ** ** * * ***
** ** ** *** * *** ** *** ** * {
* ***** **** ** * * ** *** * * *** * ******* * * * *** ** ** &a[k+1]);
    }

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


* ** *** ** * ** ** * ** * * * * {
* ** ** ** *** * ** ** * * * *** *** * *** printf(" ");
* *** * * * * * ******* * ** * * *** * * *** ***** * * *** * a[i]);
** * * * ** **** *** * * *** *** * * ***** ***** *
    }
}
answered by (-120 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 * *** *** *

int main(){
    int i,j,c,k;
    int a[50],q[50];
    * ** ** * ** **** * *
* **** *** * * ** ** * ** ( c = 0 ; c < k ; c++ ){
* * * ** * ** ** ** ** ** ** *** * **** ***** * * * * * *** * * * ** ***
*** *** * ** * * ** **
* * * *** * * ** * * ** *** * **
** * *** * * *** * ***** * ** *** ***
* **** ** * **** ****** *** * * ** ** *
* * * * *** ** ** *** ** * **** * *
*** * *** * ** *** ** * ***** *** ** * * ** *** *** a[j]);
** * * ** **
}
answered by (-32 points)
edited by
0 0
prog.c: In function 'main':
prog.c:16:2: warning: 'gets' is deprecated [-Wdeprecated-declarations]
  gets(q);
  ^~~~
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__;
              ^~~~
/tmp/ccNTa7r7.o: In function `main':
prog.c:(.text+0x6f): warning: the `gets' function is dangerous and should not be used.
0 0
prog.c: In function 'main':
prog.c:10:7: error: conflicting types for 'q'
  char q[50] = { 0 };
       ^
prog.c:8:10: note: previous declaration of 'q' was here
  int i,j,q;
          ^
prog.c:14:10: warning: format '%d' expects argument of type 'int *', but argument 2 has type 'char (*)[50]' [-Wformat=]
  scanf("%d",&q);
          ^
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: 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
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main(){
    int a,c;
*** * * *** ** * *** ** *** **** * *****
* *** * * ** *** * * b[a];
* ***** * * ** ** *** ** * ** * * *
* *** * **** * * ** * * **** * *** ** * * * ** ** *** * * * *
    }
** * ****** * **** ** **
* * ** ** * ** ****** *** * * * * * * * ** *
**** ** *** * * * ** * * **** * * * *** * *
* *** ** * * * * * ** * * * ** ** * * * * ** **
    }
* **** ** ** **** ** * ** ** ** ** *
*** ** * * * ** ** * ** *** ** * * * *
** * * * ** * **** ** * **** * ** * * ** * * * *** * * ** ** ** * * ** *** *
** * * * ** *** ** * ** **** * **** * ***
*** * * **** ** ** ** * ** ** * * * * ** ********* ** *** * **** * * %d",b[c]);
    }
* *** * * * * ** ** * ** 0;
}
answered by (-498 points)
edited by
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
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.179.46
©2016-2025

Related questions

0 like 0 dislike
55 answers
[Exercise] Coding (C) - asked Nov 29, 2017 in Chapter 8: Arrays by semicolon (5.2k points)
ID: 34968 - Available when: 2017-11-30 18:00 - Due to: Unlimited
| 6.4k views
0 like 0 dislike
46 answers
[Exercise] Coding (C) - asked Nov 29, 2017 in Chapter 9: Functions by semicolon (5.2k points)
ID: 34912 - Available when: 2017-12-14 18:00 - Due to: Unlimited
| 5k views
0 like 0 dislike
31 answers
[Exercise] Coding (C) - asked Dec 28, 2017 in Chapter 8: Arrays by semicolon (5.2k points)
ID: 39985 - Available when: Unlimited - Due to: Unlimited
| 4.9k views
0 like 0 dislike
102 answers
[Exercise] Coding (C) - asked Dec 28, 2017 in Chapter 8: Arrays by semicolon (5.2k points)
ID: 39984 - Available when: Unlimited - Due to: Unlimited
| 10.2k views
12,783 questions
183,443 answers
172,219 comments
4,824 users