U E D R , A S I H C RSS

How Many Zeros And Digits/김회영

소스 코드

~cpp 

#include<iostream>
using namespace std;

struct info_number
{
	int zero_count;
	int	total_count; 
};	

int factorial(int);
void test(int,int,info_number*);

void main()
{
	int number,result_number,radix;
	info_number temp;
	
	cout<<"팩토리얼을 구할 수와 진수를 차례대로 입력해주세요";
	cin>>number>>radix;
	
	result_number=factorial(number);	
	test(result_number,radix,&temp);

	cout<<"0의 갯수와 숫자의 갯수를 차례대로 출력합니다.\n";
	cout<<temp.zero_count<<","<<temp.total_count;
	cout<<endl;
}

int factorial (int n)
{
	if(n>1)
		return n*factorial(n-1);
	else 
		return 1;
}	

void test(int n,int radix,info_number* temp)
{
	int zero_count=0;
	int total_count=1;

	while(n>radix)
	{
		if(n%radix==0)
			zero_count++;
		n = n/radix;
		total_count++;
	}
	(*temp).total_count=total_count;	
	(*temp).zero_count=zero_count;
}

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:25
Processing time 0.0069 sec