码迷,mamicode.com
首页 > 编程语言 > 详细

倒三角算法

时间:2018-06-11 18:54:29      阅读:272      评论:0      收藏:0      [点我收藏+]

标签:str   ber   stream   不能   out   amp   i++   int   习题   

刷题ing,碰到这么一个经典习题。知道是个for循环,想着能不能用while做出来,越想越困,算了,还是for吧。。。

#include <stdio.h>
#include "stdafx.h"
#include <iostream>
#include<time.h>
using std::cin;
using std::cout;
int main() {
    int n;
    cout << "Please enter a number less than 21:" << std::endl;
    cin >> n;
    if (0 <= n && n <= 20) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j < i; j++) {
                cout << " ";
            }
            for (int k = i; k <= 2 * n - i; k++) {
                cout << "*";
            }
            cout << std::endl;
        }
    }
    else
        cout << "The number is wrong!!!" << std::endl;
}

 

 

有些头文件是做别的题遗留下来的,请勿见怪~~

倒三角算法

标签:str   ber   stream   不能   out   amp   i++   int   习题   

原文地址:https://www.cnblogs.com/NK-007/p/9168441.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!