编写一个函数,函数接受一个整型参数N,则返回一个包含N个字符的字符串,字

编写一个函数,函数接受一个整型参数N,则返回一个包含N个字符的字符串,字符串中依次存放字符’A’、’B’、’C’…
要运行出来的!!!!

#include<iostream>
using namespace std;
char*f(int n)
{

static char a[26];
memset(a,0,sizeof(a));
for(int i=0;i<n;i++)
a[i]=char(65+i);
return a;
}
int main()
{
int n;
while(cin>>n&&n!=0)
cout<<f(n)<<endl;
return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-06-15
调试。。成功。。
#include <stdlib.h>
#include <stdio.h>
char ch[200];
int fn(int n)
{
int j;
char a='A';
for(j=0;j<n;j++)
{ch[j]=a;a++;}
}
int main()
{
int x,i;
scanf("%d",&x);
fn(x);
for(i=0;i<x;i++)
printf("%c ",ch[i]);
system("pause");
}