1,2,3,4,5输出

来源:互联网 发布:谭浩强c语言视频讲解 编辑:程序博客网 时间:2024/05/02 00:11
// consoletest.cpp : Defines the entry point for the console application.//#include "stdafx.h"//cout result/*       1                          1 2 1                       1 2 3 2 1                    1 2 3 4 3 2 1                 1 2 3 4 5 4 3 2 1              1 2 3 4 5 6 5 4 3 2 1*/#include <iostream.h>void main(){    int n;cout<<"请输入一整数:"<<endl;cin>>n;    for(int a=1;a<=n;a++)    {        for(int b=1;b<=(2*n-1-(2*a-1))/2;b++){  cout<<" ";}for (int c=1;c<=a;c++){cout<<c;}//result1:// 请输入一整数:// 8// 1//        12//      123//    1234//  12345//                     123456//                   1234567//                 12345678//  Press any key to continuefor(int d=a;d>1;d--){cout<<(d-1);}cout<<endl;    }    }//备注:n:表示要显示多少行   a:表示行数,b和c,d显示列数//每行显示的数字个数:2*a-1//每行要显示总数目是:2*n-1//每行数字左边空格数:((2*n-1)-(2*a-1))/2//本程序适用于(0--9之间),假如大于10的话就会不对称了。//QQ:253261362
原创粉丝点击