C++指针/引用编程问题

来源:百度知道 编辑:UC知道 时间:2024/06/20 12:35:56
要求用指针/引用法编写下列程序
1、有n个整数,使前面各数顺序向后移m个位置,最后m个数变成最前面m个数。写一函数,实现以上功能,在主函数中输入n个整数,并输出调整后的n个整数。
2、有一字符串,包含n个字符。写一函数,将此字符串中从第个字符开始的全部字符复制成为另一个字符串。
拜托,请一定用标准的C++语言写程序.

2.
#include <stdio.h>
#include <string.h>

char* strncpy(char* scr,int n)
{
char *temp=scr;
int len=strlen(scr);
if (n<1 || n>len) return NULL;

for (int i=n,j=0;i<=len;i++,j++)
{
temp[j]=scr[i-1];
}
temp[j]=0;
return temp;
}

int main()
{
char* scr="Hello";
printf("%s\n",strncpy(scr,2));
return 0;
}

1.#include <iostream>

using namespace std;
//************************************************************************
void GetData(int *array, int n)//从 键盘上输入数据
{
for(int i = 0;i < n;i++)
{
cin>>array[i];
}
cout<<endl;
}

//************************************************************************
void ExChange(int &a ,int &b)//交换值,这里采用引用传值
{
int temp;
temp = a;
a= b;
b= temp;
}