C++编程~~关于函数

来源:百度知道 编辑:UC知道 时间:2024/06/03 20:17:19
有n个整数,使前面各数顺序向后移m个位置,最后m个数变成最前面m个数。写一函数实现以上功能,在主函数中输入n个整数和输出调整后的n个数。

/*********************************************************
**@author: Lazy_sleeping
**@date: 2009-5-4
**@version: v1.0
**********************************************************/

#include <iostream>

using namespace std;

int main()
{
const int N = 10;
int num[N] = {0,1,2,3,4,5,6,7,8,9};
int tmpNum[N] = {0};
int pos;

cout << "please input the number(1-10):";
cin >> pos;

int tmpPos = 0;
for(int i = pos; i < 10; )
{
tmpNum[tmpPos++] = num[i++];
}

for (int j = 0; j < pos;)
{
tmpNum[tmpPos++] = num[j++];
}

cout << "the result: " << endl;

for (int k = 0; k < 10;)
{
cout << tmpNum[k++];
}
cout << endl;

return 0;
}

#include "stdio.h"
#include<stdlib.h>
m