...
void func(int *A)
{
int i,temp;
temp = A[7];
for(i=7;i>0;i--)
A[i]=A[i-1];
A[0]=temp;
}
...
: : 6.Write a function in C or Java that right rotates the contents of a given
: : integer array. For example,
: : if A = {45, 23, 11, 87, 4, 6, 26, 10}, then we have A = {10, 45, 23, 11, 87,
: : 4, 6, 26} after it has been right rotated.
: #include <stdio.h>
: #include <stdlib.h>
: int main()
: {
: int i,j;
: int A[8]={45,23,11,87,-4,6,26,10};
: int B[8]={};
: for(i=0; i<8; i++)
: {
: B[i]=A[i];
: }
: for(i=0,j=7; i<8; i++,j--)
: {
: A[i]=B[j];
: }
: printf("%d,%d,%d,%d,%d,%d,%d,%d",A[0],A[1],A[2],A[3],A[4],A[5],A[6],A[7]);
: system("pause");
: return 0;
: }
: 這題我用直覺解,感覺很像白痴,不知道跟題目要的一不一樣@@
: 請各位指教 :)
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.119.162.51