生成英文字母表中的字母

发布于 2024-12-09 21:58:22 字数 115 浏览 2 评论 0原文

我有作业要写,要求我编写一个程序来生成英语字母表的前 15 个字母。我无法删除并设置 15 个不同的变量或常量。这些字母必须显示在用户最初设置的许多列中。数字必须按列对齐。有人可以帮忙吗?列数最大为 7,最小为 1。

I have homework due that states that I need to write a program that generates the first 15 letters of the english alphabet. I can't delcare and set 15 different variables or constants. The letters must be displayed in a number of columns initially set by the user. the numbers have to be aligned in columns. Can anyone help? Maximum number of columns is 7 and the minimum is 1.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

翻身的咸鱼 2024-12-16 21:58:23

这里有一些伪代码可以帮助您入门。阅读它,理解它,然后尝试实施它。

get numcols from user
if numcols < 1 or numcols > 7:
    print error and exit

ch = 'a'
for count = 1 to 15:
    output ch followed by space
    add 1 to ch
    if count is an integral multiplier of numcols:
        output newline
    endif
endfor
if numcols is not equal to 3 or 5:
    output newline
endif

它的定位大约是你的家庭作业的水平(没有花哨的东西和最小的尴尬),并且应该很好地映射到 C 代码中。

作为此实现的一部分,您应该研究:

  • 'a' 这样的字符常量实际上是伪装的整数。
  • 余数或模 (%) 运算符以及它们在这里如何/为何有用。
  • 使用 scanf 获取用户输入。
  • putchar 用于输出字符。
  • 为什么你有最后的 if 语句:-)

Here's some pseudo-code to get you started. Read it, understand it, then try to implement it.

get numcols from user
if numcols < 1 or numcols > 7:
    print error and exit

ch = 'a'
for count = 1 to 15:
    output ch followed by space
    add 1 to ch
    if count is an integral multiplier of numcols:
        output newline
    endif
endfor
if numcols is not equal to 3 or 5:
    output newline
endif

It's pitched at about the level of your homework (no fancy stuff and the smallest hint of awkwardness) and should map reasonably well into C code.

As part of this implementation, you should research:

  • the fact that character constants like 'a' are really integers in disguise.
  • remainder or modulus (%) operators and how/why they are useful here.
  • getting user input with scanf.
  • putchar for outputting characters.
  • why you have that final if statement :-)
如痴如狂 2024-12-16 21:58:23

这里提示一下:

A的ASCII码是65,B是66,C是67等等。您可以从 65 开始循环执行 15 次迭代。

Here is a hint:

ASCII code of A is 65, B is 66, C is 67 and so on. You can do it in a loop starting from 65 and going on for 15 iterations.

太阳男子 2024-12-16 21:58:23

这可以通过两个嵌套循环来完成,一个用于垂直,一个用于水平。由于数字的值是按顺序排列的,因此您可以每次增加字符的变量。

我不想放弃更多,除非另一个用户说我应该放弃。我已经提供了很多帮助,我相信你可以弄清楚剩下的事情。

如果您觉得需要更多帮助,我会尽量不提供太多帮助,但会进行更多解释。

This can be done with two nested loops, one for the vertical and one for the horizontal. since the numbers are in sequence in value you can increment the variable for the character each time.

I don't want to give away more than that unless another user says I should. I've already given a lot of help and I'm sure you can figure out the rest.

If you feel you need more help I'll try to not give too much but explain more.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文