搜索
查看: 1203|回复: 2
打印 上一主题 下一主题

【第四章第6节】动手试一试 题解

[复制链接]
跳转到指定楼层
楼主
发表于 2015-8-31 02:41:03 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 sujx 于 2015-8-31 02:45 编辑

1、请尝试用while循环打印下面的图形
[mw_shl_code=c,true]#include <stdio.h>
#include <stdlib.h>
int main()
{
        int a,b;
    a=1;
    while(a<=5)
    {
        b=1;
                while (b<=a)
        {
                        printf("%-1d ",a);
            b++;
        }
        printf("\n");
        a++;
    }
        system("pause");
        return 0;
}
[/mw_shl_code]
2、请尝试用while循环打印下面的图形

[mw_shl_code=c,true]#include <stdio.h>
#include <stdlib.h>
int main()
{
        int a,b,s;
    a=1;
    s=1;

    while(a<=5)
    {
        b=1;
                while (b<=a)
        {
                        printf("%-1d ",s);
            s++;
                        b++;
        }
        printf("\n");
        a++;
    }
        system("pause");
        return 0;
}[/mw_shl_code]



沙发
发表于 2017-9-30 13:47:27 | 只看该作者
#include <stdio.h>
#include <stdlib.h>
int main()
{      
    int a,b,n;
    a=1;
    scanf("%d",&n);//输入数字:n
    system("cls");
    while(a<=n)//输出行数:n
        {           
                        b=1;
            while(b<=a)//输出数的个数为行数
                                {        
                                        printf("%d ",a);
                                        b=b+1;
                 }
                printf("\n");
                a=a+1;
                }

system("pause");
return 0;
}
板凳
发表于 2017-9-30 13:58:30 | 只看该作者
#include <stdio.h>
#include <stdlib.h>
int main()
{      
    int a,b,c,n;
    a=1;
    c=1;
    scanf("%d",&n);//输入数字:n
    while(a<=n)//输出行数:n
        {           
            b=1;
            while(b<=a)//输出数的个数为行数
                                {        
                                        printf("%d ",c);
                                        b++;
                    c++;//输出数逐个加1
                 }
                printf("\n");
                a=a+1;
                }
system("pause");
return 0;
}
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

广播台
特别关注
快速回复 返回顶部 返回列表