教了与50多次

回复帖子

@俗人温~ 2021-04-08 22:56 回复
/*
#include<iostream> 
using namespace std;
int main()
{
    int a;
    cin>>a;
    if (a==2)
    {
    cout<<"0102"<<endl;
    cout<<"0304"<<endl;
    cout<<" "<<endl;
    cout<<"  01"<<endl;
    cout<<"0203"<<endl;
    }
    else if (a==3)
    {
    cout<<"010203"<<endl;
    cout<<"040506"<<endl;
    cout<<"070809"<<endl;
    cout<<" "<<endl;
    cout<<"    01"<<endl;
    cout<<"  0203"<<endl;
    cout<<"040506"<<endl;
    }
    else if (a==4)
    {
    cout<<"01020304"<<endl;
    cout<<"05060708"<<endl;
    cout<<"09101112"<<endl;
    cout<<"13141516"<<endl;
    cout<<" "<<endl;
    cout<<"      01"<<endl;
    cout<<"    0203"<<endl;
    cout<<"  040506"<<endl;
    cout<<"07080910"<<endl;
    }
    else if (a==5)
    {
    cout<<"0102030405"<<endl;
    cout<<"0607080910"<<endl;
    cout<<"1112131415"<<endl;
    cout<<"1617181920"<<endl;
    cout<<"2122232425"<<endl;
    cout<<" "<<endl;
    cout<<"        01"<<endl;
    cout<<"      0203"<<endl;
    cout<<"    040506"<<endl;
    cout<<"  07080910"<<endl;
    cout<<"1112131415"<<endl;
    }
    else if (a==6)
    {
    cout<<"010203040506"<<endl;
    cout<<"070809101112"<<endl;
    cout<<"131415161718"<<endl;
    cout<<"192021222324"<<endl;
    cout<<"252627282930"<<endl;
    cout<<"313233343536"<<endl;
    cout<<"  "<<endl;
    cout<<"          01"<<endl;
    cout<<"        0203"<<endl;
    cout<<"      040506"<<endl;
    cout<<"    07080910"<<endl;
    cout<<"  1112131415"<<endl;
    cout<<"161718192021"<<endl;
    }
    else if (a==7)
    {
    cout<<"01020304050607"<<endl;
    cout<<"08091011121314"<<endl;
    cout<<"15161718192021"<<endl;
    cout<<"22232425262728"<<endl;
    cout<<"29303132333435"<<endl;
    cout<<"36373839404142"<<endl;
    cout<<"43444546474849"<<endl;
    cout<<" "<<endl;
    cout<<"            01"<<endl;
    cout<<"          0203"<<endl;
    cout<<"        040506"<<endl;
    cout<<"      07080910"<<endl;
    cout<<"    1112131415"<<endl;
    cout<<"  161718192021"<<endl;
    cout<<"22232425262728"<<endl;
    }
    else if (a==8)
    {
    cout<<"0102030405060708"<<endl;
    cout<<"0910111213141516"<<endl;
    cout<<"1718192021222324"<<endl;
    cout<<"2526272829303132"<<endl;
    cout<<"3334353637383940"<<endl;
    cout<<"4142434445464748"<<endl;
    cout<<"4950515253545556"<<endl;
    cout<<"5758596061626364"<<endl;
    cout<<" "<<endl;
    cout<<"              01"<<endl;
    cout<<"            0203"<<endl;
    cout<<"          040506"<<endl;
    cout<<"        07080910"<<endl;
    cout<<"      1112131415"<<endl;
    cout<<"    161718192021"<<endl;
    cout<<"  22232425262728"<<endl;
    cout<<"2930313233343536"<<endl;
    }
    else 
    {
    cout<<"010203040506070809"<<endl;
    cout<<"101112131415161718"<<endl;
    cout<<"192021222324252627"<<endl;
    cout<<"282930313233343536"<<endl;
    cout<<"373839404142434445"<<endl;
    cout<<"464748495051525354"<<endl;
    cout<<"555657585960616263"<<endl;
    cout<<"646566676869707172"<<endl;
    cout<<"737475767778798081"<<endl;
    cout<<" "<<endl;
    cout<<"                01"<<endl;
    cout<<"              0203"<<endl;
    cout<<"            040506"<<endl;
    cout<<"          07080910"<<endl;
    cout<<"        1112131415"<<endl;
    cout<<"      161718192021"<<endl;
    cout<<"    22232425262728"<<endl;
    cout<<"  2930313233343536"<<endl;
    cout<<"373839404142434445"<<endl;
    }
return 0;    
}
*///只得了80分
#include <iostream>

using namespace std;

int main()
{
    int a,b=1,b1=1;//a表示行列数,b表示输出数
    cin>>a;
    for (int i;i<a;i++)//循环输出a行
    {
        for (int j=0;/*使每次循环都从零开始*/j<a;j++)//循环输出每一行

        {
            if (b<10)
            cout<<0<<b;
            else
            cout<<b;
            b++;
        }
        cout<<endl;//循环完成一行后,换行
    }//正方形
        cout<<endl;
        for (int y;y<a;y++)
    {
            for (int l=0;l<a-y-1;l++)//空格倒三角
        {
            cout<<"  ";//两个空格
        }          
            for (int v=0;v<=y;v++)//数字正三角
        {
            if (b1<10)
            cout<<0<<b1;
            else
            cout<<b1;
            b1++;
        }
        cout<<endl;
    }//三角形
    return 0;
}//没开O2零分
@Fеe_cle6418  2021-04-09 08:01 回复 举报

第一份代码 $a$为1你没有输出

第二份代码你的变量 $i$和 $y$在循环开始的时候都没有初始值

反馈
如果你认为某个帖子有问题,欢迎向洛谷反馈,以帮助更多的同学。



请具体说明理由,以增加反馈的可信度。