如何在string 里附值进循环的字母

来源:百度知道 编辑:UC知道 时间:2024/06/28 03:01:43
一道C语言题目
最好能指导下思路饿
比如
i='A'
i=i+1
要求输入
str["ABCD..."]
全题如下

A Pattern of Letters

void letters(char c)
// c is one of the characters 'A' through 'Z'.
// The function needs to print a pattern of letters as follows:
// 1. If the parameter c is 'A', then the output is 'A'.
// 2. For other values of c, the output consists of three parts:
// -- the output for the previous letter (c-1);
// -- followed by the letter c itself;
// -- followed by a second copy of the output for the previous letter (c-1).
// There is no '\n' printed at the end of the output.
/* Example output:
letters('D') will print:
ABACABADABACABA
*/
谢谢回答啊 我是学C的新手 不用STRING的话能不能用递归 ? 下面的这个程序实在看不懂= =。。。。

#include <iostream>
using namespace std;
void letters(char c)
{
if(c == 'A')
cout << c;
else
{
cout << letters(c-1);
cout << c;
cout << letters(c-1);
}
return;
}
int main()
{
char ch;
cin >> ch;
letters(ch);
return 0;
}
既然你用string,那一定是C++吧,但是这道题不需要用string啊~

A Pattern of Letters 字母造型

void letters(char c)
// c is one of the characters 'A' through 'Z'. 参数c是一个A-Z的字母
// The function needs to print a pattern of letters as follows: 这个函数打印出如下所需的字母排列
// 1. If the parameter c is 'A', then the output is 'A'. 1.如果参数c是‘A',那么输出'A'
// 2. For other values of c, the output consists of three parts:2.对其他字母来说,输出由下面3部分构成:
// -- the output for the previous letter (c-1); 先输出letter(c-1)
// -- followed by t