我如何...盒子在盒子里,因为我只有一个盒子,但内盒没有被填满 [英] How do i...box in a box as I only got a box but the inner boxes are not getting filled

查看:109
本文介绍了我如何...盒子在盒子里,因为我只有一个盒子,但内盒没有被填满的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想法是取一个数字作为输入并打印一个盒子的模式



如果输入为2,则两个盒子要打印在另一个内部



最小的盒子大小为3 * 3,下一个大盒子将是5 * 5,下一个盒子将是7 * 7,依此类推/>


输入1,然后画一个尺寸为3 * 3的盒子



对于输入2,外盒将是5 * 5,内部将是3 * 3



对于输入3,外盒将是7 * 7,另外还有2个内盒



因此对于n,最外面的盒子将是n * 2 + 1大小,带有(n1)个内盒子



所有盒子将左上角对齐,如图所示



输入格式:



第一行输入包含一个数字N



输出格式:



打印N个嵌套的盒子



限制条件:



1. 0< N< 25



我的尝试:



Idea is to take a number as input and print a pattern of boxes

If input is 2, two boxes are to be printed ­ one inside the other

Smallest box will be of size 3*3, the next bigger box will be 5*5, the next one will be 7*7, so on and so forth

For input 1, then draw a box of dimensions 3*3

For input 2, outer box will be 5*5, inner will be 3*3

For input 3, outer box will be 7*7, with 2 more inner boxes

So for n, outermost box will be n*2 +1 in size, with (n­1) inner boxes

All boxes will be top left aligned as shown in the figure

Input Format:

First line of input contains a number N

Output Format:

Print N nested boxes

Constraints:

1. 0 < N < 25

What I have tried:

#include<stdio.h>
#include<conio.h>
int main()
{
    int j,i,n;
    scanf("%d",&n);
    for(j=0;j<n-2;j++)>
        printf("-");
    printf("\n");

    for(i=0;i<n;i++)>
    {
        printf("-");
        for(j=0;j<n-2;j++)>
            printf(" ");
        printf("-\n");
    }
    for(j=0;j<n;j++)>
        printf("-");
    printf("\n");
    //}
    return(0);
}

推荐答案

我将给你两个小时前给同学的完全相同的答案:



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



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



如果遇到具体问题,请询问相关问题,我们会尽力提供帮助。但是我们不会为你做这一切!



但是...一些想法让你开始。

Draw一些手工盒子看看它们的样子:

I'm going to give you the exact same answer I gave your classmate two hours ago:

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!

But...a few ideas to get you started.
Draw a few of the boxes by hand to see what they look like:
***
* *
***




*****
*****
** **
*****
*****




*******
*******
*******
*** ***
*******
*******
*******

而且很明显发生了什么:所有的行都是实心的,除了中间的一行,中间只有一个空白。

从那,它是非常简单:一个外部循环绘制每一行,两个内部循环绘制线的左半部分和右半部分,但决定在行的中间打印星形或空格。

试一试:它并不像你想象的那么难!

And it's pretty obvious what is happening: all the rows are solid, except the centre one which contains a single blank in the middle.
From that, it's pretty simple: One outer loop to draw each line, and two inner loops to draw the left and right halves of the line but a decision to print a star or a space in the middle of the line.
Try it: it isn't as difficult as you think!


你真的不明白你需要做什么。

- 拿一张纸并绘制你想要的输出n = 1,2,3,4和5

You don't really understand what you need to do.
- Take a sheet of paper and draw the output you want for n= 1, 2, 3, 4 and 5
+---+
|+-+|
|| ||
|+-+|
+---+



并推断您需要编程以再现相同的图纸。


and deduce what you need to program to reproduce the same drawing.


这篇关于我如何...盒子在盒子里,因为我只有一个盒子,但内盒没有被填满的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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