ons
2 Decimal to N-Base Conversion
Hide problem statement «
Problem statement
Instr
N-base notation is a system for writing numbers which uses only n
different symbols. These symbols are the first n symbols from the
given notation list (including the symbol for 0). Decimal to n-base
notations are {0:0, 1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8, 9:9, 10:A,
11:B and so on up to 35:Z).
Implement the following function:
char* DectoNBase(int n, int num);
Now
2.
GLAR
The function accepts positive integers 'n' and 'num'. Implement the
function to calculate n-base equivalent of 'num' and return the same
as a string
Steps:
1. Divide the decimal number num by n. Treat the division as
an integer division,
2. Write down the remainder (in n-base notation).
DEBIT
ಸಿಪಿ
695
G
eru 99
POLISI
DIPE
3. Divide the quotient again by n. Treat the division as an
Integer division
2
3
4
5
6
GEN
4. Repeat step 2 and 3 until quotient is 0.
5. The n-base value is the sequence of the remainders from the
last to first
Assumption: 1< n == 36
Example:
Input:
12
13
13
num: 718
Output:
ABA
Answers
Answered by
0
Answer:
I cannot understand
write properly
Answered by
0
Answer:
#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
// adding 1.
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;
}
Similar questions