1.
#include <iostream> // .h 를 안붙여도 된다
int main(void) {
int num = 20;
std::cout << "hello world!" << std::endl; // 개행문자 = std::endl
std::cout << "hello" << " world" << std::endl;
std::cout << num << "" << 'A';
std::cout << "" << 3.14 << std::endl;
return 0;
}
hello world!
hello world
20A3.14
2.
#include <iostream>
int main(void) {
int val1;
std::cout << "Insert first number : ";
std::cin >> val1;
int val2;
std::cout << "Insert second number : ";
std::cin >> val2;
int result = val1 + val2;
std::cout << "result : " << result << std::endl;
return 0;
}
Insert first number : 5
Insert second num : 6
result : 11
3.
#include <iostream>
int main(void) {
int val1, val2;
int result = 0;
std::cout << "Insert Two Number : ";
std::cin >> val1 >> val2;
if(val1 < val2) {
for(int i = val1 + 1;i < val2;i++)
result += i;
}
else {
for(int i = val2 + 1;i < val1;i++)
result += i;
}
std::cout << "Sum between two number : " << result << std::endl;
return 0;
}
Insert Two Number : 0 11
Sum between two number : 55
4.
#include <iostream>
int main(void) {
char name[100];
char lang[100];
std::cout << "Insert your name : ";
std::cin >> name;
std::cout << "Insert your favorite language : ";
std::cin >> lang;
std::cout << "Your name is " << name << std::endl;
std::cout << "Your favorite language is " << lang << std::endl;
return 0;
}
Insert your name : gaffel
Insert your favorite language : KOREAN
Your name is gaffel
Your favorite language is KOREAN
'Programming > C++' 카테고리의 다른 글
함수오버로딩 (0) | 2011.04.08 |
---|