C++学习笔记01-循环判断


#include "pch.h"
#include <iostream>
#include<string>
#include<limits>
using namespace std;


int func1(int h);
int func2(int h);



int main()
{
	func1(16);
	func2(16);
	
	return 0;
}

int func1(int h)
{
	for (int n = 1; n <= h; n++)
	{
		for (int i = 1; i <= h - n; i++)
		{
			printf(" ");
		}
		for (int i = 1; i <= 2 *n - 1; i++)
		{
			cout << "*";
		}
		
		cout << endl;
	}
	return 0;
}

int func2(int h)
{
	for (int i = 1; i <= h;i++)
	{
		for (int j = 1; j <=h+i - 2; j++)
		{
			if (j == (h -i + 1))
			{
				cout << '*';
				if (i == h)
				{
					for (int j = 1; j <= 2 * i - 3; j++)
					{
						cout << "*";
					}
					break;
				}
				continue;
			}
			
			cout << " ";
			
			
		}
		
		cout << "*\n";
	}
	cout << endl;
	return 0;
}

项目需要用python调用c的接口,于是趁此机会看看c++。

猜你喜欢

转载自blog.csdn.net/q275343119/article/details/87854438