명품 C++ Programming 실습문제 ch01

2022. 11. 29. 17:47언어(Language)/c++

[1번]

#include <iostream>
int main() {
	std::cout << "My name is Mike.\n";
	return 0;
}

 

 

 

 

[2번]

#include <iostream>
using namespace std;
int main() {
	cout << "컴퓨터공학과"<<endl;
	cout << "21세" << endl;
	cout << "대통령" << endl;
	return 0;
}

 

 

 

[3번]

#include <iostream>
using namespace std;
int main() {
	cout << "1에서 10까지 더한 결과는 ";
	int sum = 0;
	for (int i = 1; i <= 10; i++) {
		sum += i;
	}
	cout << sum << "입니다.";
	return 0;
}

 

 

 

[4번]

#include <iostream>
using namespace std;
int main() {
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j <= i; j++) {
			cout << "*";
		}
		cout << endl;
	}
	return 0;
}