對一維陣列的5個元素進行賦值,之後將其依次往後移乙個位置,再將第五個資料放在第乙個儲存單元並輸出?

時間 2021-11-06 06:55:44

1樓:筱傑

題目沒說用什麼程式語言,我就用C寫了兩個版本。

版本一:完全符合題意要求的寫法#include

intmain

(int

argc

,const

item_t

*argv);

intn

=sizeof

(array)/

sizeof(*

array

);int

temp

=array[n

-1];for

(inti=

n-1;

i>0;

i--)array[i

]=array[i

-1];array[0

]=temp

;for

(inti=

0;i

i++)printf

("%d "

,array[i

]);return0;

}輸出:

5 1 2 3 4

版本二:陣列元素移動,擴充套件寫法#include

#include

#include

typedef

intitem_t

;void

arraySwap

(item_t

*data

,inti,

intj)}

void

arrayReverse

(item_t

*data

,int

length

)void

arrayMove

(item_t

*data

,int

length

,int

offset

,bool

isLoop

)else

}else

elseif(

offset

>0)for(

inti=0

;i

++)data[i

]=0;

}else

for(

inti

=length-1

;i>=

length

+offset;i

--)data[i

]=0;

}}}void

arrayRange

(item_t

*data

,int

length

,int

start

)void

arrayShow

(item_t

*data

,int

length

)void

testMove

(item_t

*data

,int

length

,int

offset

,bool

isLoop

)int

main

(int

argc

,const

item_t

*argv

)輸出:

Raw Array:

1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8

offset=1, isLoop=0

0 0 0 0 1 2 3 4 5

offset=3, isLoop=0

0 1 2 3 4 5 0 0 0

offset=-3, isLoop=0

0 0 0 0 0 0 0 0 0

offset=-20, isLoop=0

Raw Array:

1 2 3 4 5 6 7 8 9

9 1 2 3 4 5 6 7 8

offset=1, isLoop=1

6 7 8 9 1 2 3 4 5

offset=3, isLoop=1

9 1 2 3 4 5 6 7 8

offset=-3, isLoop=1

2 3 4 5 6 7 8 9 1

offset=-20, isLoop=1

如何找出乙個陣列中兩個不相鄰元素的和的最大值

TiiWoo include 遍歷一遍,O n 的複雜度 include using namespace std const intINF 1e9 intn intarr 110 int ans,tmp,maxx INF intmain cout endl return0 Aperodry 先從陣列...

對每一維的特徵進行歸一化和對每個樣本的各維特徵歸一化有什麼區別?

一名 一般來說,列是特徵 行是樣本。按列處理應該是比較常見的,因為這樣的話,某一樣本的某特徵和其他樣本相比仍然不會丟失資訊。而如果是按行來,處理後該特徵的資訊可能會被自身其他資料淹沒了。總之,是要和其他樣本來對比的,所以要用列。舉個例子,比如 2個樣本,每個有3個特徵。2,3,30 0.6,3,5 ...

c 如何自定義乙個返回二維陣列的函式而不是首位址?

如果你說的是內建陣列,那是不可以的。但是,如果你願意可以使用C 11標準模板庫裡面的array,封裝成了模板類,提供了拷貝建構函式,可以直接返回乙個array。 旺旺 C 語言標準裡面倒是真寫了函式不能返回陣列,在 版標準裡沒看到相關論述,在 版標準裡面看到了,函式不能返回陣列,但可以返回對陣列的引...