1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>
using namespace std;
 
int main() {
    string line;
    while (1) {
        cout << "종료하고싶으면 yes를 입력하세요>>";
        getline(cin, line);
        if (line == "yes") {
            cout << "종료합니다.." << endl;
            break;
        }
    }
}
cs


1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <string>
using namespace std;
 
int main() {
    string f, nf;
    cout << "새 암호를 입력하세요>>";
    getline(cin, f);
    cout << "새 암호를 다시 한 번 입력하세요>>";
    getline(cin, nf);
    f == nf ? cout << "같습니다" << endl : cout << "다릅니다" << endl;
}
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>
using namespace std;
 
int main() {
    string line;
    cout << "문자들을 입력하라" << endl;
    getline(cin, line);
    int len = line.length();
    int count = 0;
    for (int i = 0; i < len; i++) {
        line[i] == 'x' ? count++ : NULL;
    }
    cout << "x의 개수는 " << count << endl;
}
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#define COUNT 5
using namespace std;
 
int main() {
    double max, num[COUNT];
    cout << "5개의 실수를 입력하라>>";
    for (int i = 0; i < COUNT; i++) {
        cin >> num[i];
    }
    for (int i = 0; i < COUNT-2; i++) {
        num[i] < num[i + 1] ? max = num[i + 1] : max = num[i];
    }
    cout << "제일 큰 수 = " << max << endl;
}
cs


1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;
 
int main() {
    int a, b;
    int max;
    cout << "두 수를 입력하라>>";
    cin >> a >> b;
    a < b ? max = b : max = a;
    cout << "큰 수 = " << max << endl;
}
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace std;
 
int main() {
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            cout << j << "x" << i << "=" << i * j << "\t";
            if (j == 9) {
                cout << endl;
            }
        }
    }
}
cs


1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;
 
int main() {
    for (int i = 1; i <= 100; i++) {
        cout << i << "\t";
        if (i % 10 == 0) {
            cout << endl;
        }
    }
}
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <string>
using namespace std;
 
int main(){
    string s;
    string a;
    cout << "가위 바위 보 게임을 합니다. 가위, 바위, 보 중에서 입력하세요." << endl;
    cout << "사또>>";
    getline(cin, s);
    cout << "아랑>>";
    getline(cin, a);
    if (s == a) cout << "비겼습니다." << endl;
    else if (s == "가위") {
        if (a == "보"cout << "사또가 이겼습니다." << endl;
        else cout << "아랑이 이겼습니다." << endl;
    }
    else if (s == "바위") {
        if (a == "가위"cout << "사또가 이겼습니다." << endl;
        else cout << "아랑이 이겼습니다." << endl;
    }
    else if (s == "보") {
        if (a == "주먹")cout << "사또가 이겼습니다." << endl;
        else cout << "아랑이 이겼습니다." << endl;
    }
}
cs


1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;
 
int main() {
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j <= i; j++) {
            cout << "*";
        }
        cout << endl;
    }
}
cs


1
2
3
4
5
6
7
8
9
10
#include <iostream>
using namespace std;
 
int main() {
    int sum = 0;
    for (int i = 1; i <= 10; i++) {
        sum += i;
    }
    cout << "1에서 10까지 더한 결과는 " << sum << "입니다" << endl;
}
cs


+ Recent posts