【发布时间】:2014-03-21 19:08:06
【问题描述】:
我正在编写一个程序,该程序打印字母然后在一个字母上移动。它将执行 26 次,因此最终看起来像这样:
1abcdefghijklmnopqrstuvwxyz
2zabcdefghijklmnopqrstuvwxy
3zxabcdefghijklmnopqrstuvwx
4zxyabcdefghijklmnopqrstuvw
到目前为止,我有一个 while 循环可以处理任何字母并打印一行字母字符串,但我不知道如何将它用于一个函数。
这是我的一封信代码:
#include <stdio.h>
int main(void)
{
char a = 'a';
char h = 'h';
char z = 'z';
int start_p;
char one = 'a';
int shift = 1;//some of these are used for later parts of my code
int end_p = 1;
int start = 0;
char two = 'a';
one = 'h';
while(one <= z)
{
printf("%c", one);
one = one + 1;
}
one = ;
while(one >= a)
{
printf("%c", one);
one = one - 1;
}
return(0);
}
【问题讨论】:
-
不应该是
3yzabcdefghijklmnopqrstuvwx和4xyzabcdefghijklmnopqrstuvw吗?如果不是,你说的转移是什么意思?
标签: c loops while-loop