如何使用for循环打印给定系列 [英] How do I print given series with for loop

查看:84
本文介绍了如何使用for循环打印给定系列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

必须使用for循环打印系列。该系列如下

A

B

C

D

。 ..

Z

AA

AB

AC

AD
..AZ

BA

BB

...



我尝试了什么:



我试图使用追加函数但得到了垃圾值

The series must be printed using for loop . The series is as follow
A
B
C
D
...
Z
AA
AB
AC
AD
..AZ
BA
BB
...

What I have tried:

I have tried to use append function but got garbage values

推荐答案

我们不做你的功课:这是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



因此,如果您需要帮助,则需要显示我们你尝试了什么,而不只是发布你的作业问题,希望我们为你排序!

首先看看递归,不要忘记添加终止条件来限制最大值字符串的长度 - 你的系列描述没有这样做,在你开始运行代码之前修复和结束是非常重要的!

首先编写一个循环来打印第一组 - A到Z - 然后考虑如何使用它来打印第二组的各个元素 - AA到AZ,BA到BZ等等 - 在你开始之前尝试编写任何代码来实现它。



亲自尝试一下,你可能会发现它并不像你想象的那么难!



如果您遇到特定问题,请询问相关问题,我们会尽力提供帮助。但是我们不会为你做这一切!
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

So if you want help, you need to show us what you tried, not just post your homework question and hope we sort it out for you!
Start by looking at recursion, and don't forget to add a "termination condition" to limit the max length of the string - your series description doesn't do that and it is extremely important to fix and end before you start running the code!
Begin by writing a loop to print the "first set" - "A" to "Z" - and then think how you can use that to print the individual elements of the "second set" - "AA" to "AZ", "BA" to BZ", and so on - before you start trying to code anything to implement it.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!


#include <stdio.h>

void main()
{
	char *str = " ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	int i;
	
	for(i = 0; i < 702; i++)
	{
		printf("%c%c\n", str[i/26], str[i%26 + 1]);
	}
}


这篇关于如何使用for循环打印给定系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆