# 给定以十进制为底的数字N，请以任意底数(底为b)查找其位数

2021年4月5日16:07:21 发表评论 549 次浏览

## 本文概述

``````Input : Number = 48
Base = 4
Output: 3
Explanation : (48)10 = (300)4

Input : Number = 1446
Base = 7
Output: 4
Explanation : (446)10 = (4134)7``````

, 如果是这样的话

or

## C ++

``````// C++ program to Find Number of digits
// in base b.
#include <iostream>
#include <math.h>
using namespace std;

// function to print number of
// digits
void findNumberOfDigits( long n, int base)
{
// Calculating log using base
// changing property and then
// taking it floor and then
int dig = ( int )( floor ( log (n) /
log (base)) + 1);

// printing output
cout << "The Number of digits of "
<< "Number " << n << " in base "
<< base << " is " << dig;
}

// Driver method
int main()
{
// taking inputs
long n = 1446;
int base = 7;

// calling the method
findNumberOfDigits(n, base);
return 0;
}

// This code is contributed by Manish Shaw
// (manishshaw1)``````

## Java

``````// Java program to Find Number
// of digits in base b.
class GFG {

// function to print number of digits
static void findNumberOfDigits( long n, int base)
{

// Calculating log using base changing
// property and then taking it
// floor and then adding 1.
int dig = ( int )(Math.floor(
Math.log(n) / Math.log(base))
+ 1 );

// printing output
System.out.println( "The Number of digits of Number "
+ n + " in base " + base
+ " is " + dig);
}

// Driver method
public static void main(String[] args)
{
// taking inputs
long n = 1446 ;
int base = 7 ;

// calling the method
findNumberOfDigits(n, base);
}
}``````

## Python3

``````# Python3 program to Find Number of digits
# in base b.

import math

# function to print number of
# digits
def findNumberOfDigits(n, base):

# Calculating log using base
# changing property and then
# taking it floor and then
dig = (math.floor(math.log(n) /
math.log(base)) + 1 )

# printing output
print ( "The Number of digits of"
" Number {} in base {} is {}"
. format (n, base, dig))

# Driver method

# taking inputs
n = 1446
base = 7

# calling the method
findNumberOfDigits(n, base)

# This code is contributed by
# Manish Shaw (manishshaw1)``````

## C#

``````// C# program to Find Number of digits
// in base b.
using System;

class GFG {

// function to print number of
// digits
static void findNumberOfDigits( long n, int b)
{
// Calculating log using base
// changing property and then
// taking it floor and then
int dig = ( int )(Math.Floor(
Math.Log(n) / Math.Log(b)) + 1);

// printing output
Console.Write( "The Number of digits"
+ " of Number " + n + " in base "
+ b + " is " + dig);
}

// Driver method
public static void Main()
{
// taking inputs
long n = 1446;
int b = 7;

// calling the method
findNumberOfDigits(n, b);
}
}

// This code is contributed by Manish Shaw
// (manishshaw1)``````

## 的PHP

``````<?php
// PHP program to Find Number
// of digits in base b.

// function to print
// number of digits
function findNumberOfDigits( \$n , \$b )
{
// Calculating log using base
// changing property and then
// taking it floor and then
\$dig = (int)( floor (log( \$n ) /
log( \$b )) + 1);

// printing output
echo ( "The Number of digits" .
" of Number " . \$n .
" in base " . \$b .
" is " . \$dig );
}

// Driver Code
\$n = 1446;
\$b = 7;

// calling the method
findNumberOfDigits( \$n , \$b );

// This code is contributed by
// Manish Shaw (manishshaw1)
?>``````

``The Number of digits of Number 1446 in base 7 is 4``