给定一个字符串char str [] = 123456789;编写一个显示模式的程序 [英] Given a string char str[ ] =123456789; write a program that displays a pattern

查看:239
本文介绍了给定一个字符串char str [] = 123456789;编写一个显示模式的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出一个字符串

char str [] = 123456789;

编写一个显示以下内容的程序:

1

2 3 2

3 4 5 4

4 5 6 7 6 5 4

5 6 7 8 9 8 7 6 5

in c编程。



我尝试过:



使用嵌套for循环并在值到达i> = n + 1后递减值

Given a string
char str[ ] =123456789;
Write a program that displays the following:
1
2 3 2
3 4 5 4 3
4 5 6 7 6 5 4
5 6 7 8 9 8 7 6 5
in c programming.

What I have tried:

using nested for loop and decrementing the values after it reaches i>=n+1

推荐答案

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



亲自尝试,你可能会发现它不是和你想的一样困难!



如果遇到具体问题,请询问相关问题,我们会尽力提供帮助。但我们不打算为你做这一切!
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.

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!


建议:学会正确缩进你的代码,它显示它的结构,它有助于阅读和理解。

Advice: Learn to indent properly your code, it show its structure and it helps reading and understanding.
#include <stdio.h>
int main()
{
	int n,i,j,k;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		for(j=i;j<n+2;j++)
		{
			if(j<n+i)
			{
				printf("%d",j);
				k=j;
			}
			else
				printf("%d",k--);
		}
		printf("\n");
	}
	return 0;
}



专业程序员的编辑器具有此功能,其他功能包括括号匹配和语法高亮。

Notepad++主页 [ ^ ]

ultraedit [ ^ ]



-----


Professional programmer's editors have this feature and others ones such as parenthesis matching and syntax highlighting.
Notepad++ Home[^]
ultraedit[^]

-----

for(j=i;j<n+2;j++)



我怀疑 n + 2 不是正确的循环结束。



当你不明白为什么你的代码没有达到预期的效果,使用调试器并查看你的代码执行。



有一个工具可以让你要查看代码正在执行的操作,其名称为调试程序。它也是一个很好的学习工具,因为它向你展示了现实,你可以看到哪种期望与现实相符。

当你不明白你的代码在做什么或为什么它做它做的时候,答案就是答案是调试器

使用调试器查看代码正在执行的操作。只需设置断点并查看代码执行情况,调试器允许您逐行执行第1行并在执行时检查变量。



调试器 - 维基百科,免费的百科全书 [ ^ ]



掌握Visual Studio 2010中的调试 - 初学者指南 [ ^ ]

使用Visual Studio 2010进行基本调试 - YouTube [ ^ ]

调试器在这里向您展示您的代码正在做什么,您的任务是与什么进行比较应该这样做。

调试器中没有魔法,它没有找到错误,它只是帮助你。当代码没有达到预期的效果时,你就会接近一个错误。


I suspect n+2 is not the correct end of loop.

When you don't understand why your code don't do what you expect, use the debugger and see your code execute.

There is a tool that allow you to see what your code is doing, its name is debugger. It is also a great learning tool because it show you reality and you can see which expectation match reality.
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.


这篇关于给定一个字符串char str [] = 123456789;编写一个显示模式的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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