c++ 복습 2-1~2-5
2-1
#include <iostream>
using namespace std;
int main() {
for (int i = 1; i <=100; i++) {
if (i % 10 == 0){
cout << i<<"\n";
}
else {
cout << i << "\t";
}
}
return 0;
}
2-2
#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";
}
cout << "\n";
}
return 0;
}
2-3
#include <iostream>
using namespace std;
int main() {
int x, y;
cout << "enter two integer>>>";
cin >> x >> y;
if (x > y)
cout << x;
else if (x < y)
cout << y;
else
cout << x << y;
return 0;
}
2-4
#include <iostream>
using namespace std;
int main() {
float x[5];
cout << "enter 5 float>>";
for (int i = 0; i < 5; i++)
cin >> x[i];
float max = x[0];
for (int i = 1; i < 5; i++)
if (max < x[i])
max = x[i];
cout << max;
return 0;
}
2-5
#include <iostream>
#include <cstring>
using namespace std;
int main(void) {
char x[100];
cout << "enter string>>";
cin.getline(x, 100, '\n');
int cnt = 0;
for (int i = 0; x[i]; i++) {
if (x[i] == 'x') {
cnt += 1;
}
}
cout << cnt;
return 0;
}