>[info]輸入數組,最大的與第一個元素交換,最小的與最后一個元素交換,輸出數組。。
~~~C
#include <stdio.h>
#include <stdlib.h>
void print_arr(int array[],int n);
void move(int array[],int n,int offset);
int main()
{
int arr[20];
int i,n,offset;
//輸入數組大小和數組內容
printf("Total numbers?\n");
scanf("%d",&n);
printf("Input %d numbers.\n",n);
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
//輸入滾動偏移量
printf("Set your offset.\n");
scanf("%d",&offset);
printf("Offset is %d.\n",offset);
//打印滾動前數組
print_arr(arr,n);
//滾動數組并打印
move(arr,n,offset);
print_arr(arr,n);
}
//打印數組
void print_arr(int array[],int n)
{
int i;
for(i=0;i<n;++i)
printf("%4d",array[i]);
printf("\n");
}
//滾動數組
void move(int array[],int n,int offset)
{
int *p,*arr_end;
arr_end=array+n; //數組最后一個元素的下一個位置
int last;
//滾動直到偏移量為0
while(offset)
{
last=*(arr_end-1);
for(p=arr_end-1;p!=array;--p) //向右滾動一位
*p=*(p-1);
*array=last;
--offset;
}
}
~~~
- C語言模塊
- 基礎入門
- 各種變量類型
- 條件編譯
- 100例
- day1
- 1.c
- 2.c
- 3.c
- 4.c
- 5.c
- 6.c
- 7.c
- 8.c
- 9.c
- 10.c
- day2
- 1.c
- 2.c
- 3.c
- 4.c
- 5.c
- 6.c
- 7.c
- 8.c
- 9.c
- 10.c
- day3
- 1.c
- 2.c
- 3.c
- 4.c
- 5.c
- 6.c
- 7.c
- 8.c
- 9.c
- 10.c
- day4
- 1.c
- 2.c
- 3.c
- 4.c
- 5.c
- 6.c
- 7.c
- 8.c
- 9.c
- 10.c
- day5
- 1.c
- 2.c
- 3.c
- 4.c
- 5.c
- 6.c
- 7.c
- 8.c
- 9.c
- 10.c
- day6
- 1.c
- 2.c
- 3.c
- 4.c
- 5.c
- 6.c
- 7.c
- 8.c
- 9.c
- 10.c
- day7
- 1.c
- 2.c
- 3.c
- 4.c
- 5.c
- 6.c
- 7.c
- 8.c
- 9.c
- 10.c
- linux基礎知識
- 目錄
- 系統設置
- ftp管理
- ftp-auth
- 進程
- ssh登錄
- 權限屬性
- 用戶/用戶組
- 安裝命令
- 數據庫操作
- 虛擬機vmvare-tools安裝
- VI命令
- 上傳下載
- error
- 虛擬機mac