C언어 삼각형 찍기

Posted by 대혀니_
2017. 10. 22. 12:39 PROGRAMING/C
#include <iostream>
using namespace std;

int main() {
	int space;
	int number = 1;
	int output;
	int line;
	for (line = 1; line <= 3; line++) {
		for (space = 1; space <= 3 - line; space++) {
			cout << "  ";
		}
		for (output = 1; output <= line * 2 - 1; output++) {
			cout << " " << number++;
		}
		cout << endl;
	}
}




#include <iostream>
using namespace std;

int main() {
	int i;
	int j;
	int k;
	int num=1;
	for (i = 1; i <= 5; i++) {
		for (j = 6-i; j >= 1; j--) {
			cout << "* ";
		}
		cout << endl;
	}
	for (i = 1; i <= 5; i++) {
		for (j = 1; j <= i; j++) {
			cout << "* ";
		}
		cout << endl;
	}
	for (i = 1; i <= 5; i++) {
		for (j = 6 - i; j >= 1; j--) {
			cout << "\t" << num++;
		}
		cout << endl;
	}
}