7.03.2017

5자리 숫자를 받아서 만원짜리 개수, 천원짜리 개수, 백원짜리 개수, 십원짜리 개수, 일원짜리 개수를 세기

//C++로 시작하는 객체지향 프로그래밍
// 5자리 숫자를 받아서 만원짜리 개수, 천원짜리 개수, 백원짜리 개수, 십원짜리 개수, 일원짜리 개수를 세기

#include <iostream>
using namespace std;
int main(){
int number, n1=0, n2=0, n3=0, n4=0, n5=0;
cin >> number;

n1 = number/10000;
cout << "만원짜리는 " << n1<< "장입니다. "<< endl;
n2 = (number%10000)/1000;
cout << "천원짜리는 " << n2<< "장입니다. "<< endl;
n3 = (number-n1*10000-n2*1000)/100;
cout << "백원짜리는 " << n3<< "개입니다. "<< endl;
n4 = number%100/10;
cout << "십원짜리는 " << n4<< "개입니다. "<< endl;
n5 = (number-n1*10000-n2*1000-n3*100-n4*10)/1;
cout << "일원짜리는 " << n5<< "개입니다. "<< endl;

system("pause");
return 0;
}




댓글 없음:

댓글 쓰기