#include <iostream>
using namespace std;
int main() {
int x, y, num =0;
char i;
cout << "숫자, 연산자, 숫자를 차례대로 입력해주세요.";
cin >> x >> i >> y;
switch (i) {
case '+':
num = x + y;
break;
case '-':
num = x - y;
break;
case '*':
num = x * y;
break;
case '/':
num = x / y;
break;
}cout << num;
=========================================================================
//세 자리 숫자 입력 후 각 자리수의 숫자 짝수, 홀수 판별하기
int x;
cout << "세 자리 숫자를 입력해주세요.";
cin >> x;
if ((x/100) %2 ==0)
cout << x/100 << " : 짝수" << endl;
else cout << x / 100 << " : 홀수" << endl;
if ((x/10) %2 ==0)
cout << x/10%10 << " : 짝수" << endl;
else cout << x / 10%10 << " : 홀수" << endl;
if (x%2 ==0)
cout << x%10 << " : 짝수" << endl;
else cout << x %10 << " : 홀수" << endl;
=========================================================================
int num = 0; // 1
while (num < 5) { //num이 5보다 작을때까지 실행
cout << num << "\n";
num++;
} // 조건식으로 이동함
cout << "반복문 종료 후 : " << num << endl;
while (num < 10) {
cout << "Hello\t";
num++;
=========================================================================
//factorial
int limit, result = 1;
cout << "숫자를 입력해주세요." << endl;
cin >> limit;
while(limit >0){
result *= limit;
limit--;
}
cout << "결과값 : "<< result << endl;
==========================================================================
//제곱근 구하기
int x, y, result = 1;
cout << "숫자와 제곱근을 입력해주세요. " << endl;
cin >> x >> y;
while(y != 0) {
result *= x;
y--;
}
cout << result;
===========================================================================
//입력한 숫자 ~100까지 출력 입력한 숫자부터 3씩 증가되는 숫자 출력
int input, result = 0;
cout << "숫자를 입력" << endl;
cin >> input;
result = input;
while (result <= 100) {
cout << result << endl;
result += 3;
}
===========================================================================
//0 누르면 stop 하게끔!
int x = 5, sum = 0;
while (x !=0) {
cin >> x;
sum += x;
} cout << "총합은 " << sum << endl;
system("pause");
return 0;
}
댓글 없음:
댓글 쓰기