`{"id":"cda6687d-fc21-4aa2-9449-d2da391ddb68","name":"Decimal To Any Base","description":"1. You are given a decimal number n.\r\n2. You are given a base b.\r\n3. You are required to convert the number n into its corresponding value in base b.","inputFormat":"A number n\r\nA base b","outputFormat":"A number representing corresponding value of n in number system of base b","constraints":"0 &lt;= d &lt;= 512\r\n2 &lt;= b &lt;= 10","sampleCode":{"cpp":{"code":"#include<iostream>\nusing namespace std;\nint DecToAny(int n, int b){\n//write your code here\n}\nint main(){\n int n;\n int b;\n cin >> n;\n cin >> b;\n int res = DecToAny(n,b);\n cout << res << endl;\n}"},"java":{"code":"import java.util.*;\r\n \r\n public class Main{\r\n \r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int b = scn.nextInt();\r\n int dn = getValueInBase(n, b);\r\n System.out.println(dn);\r\n }\r\n \r\n public static int getValueInBase(int n, int b){\r\n // write code here\r\n }\r\n }"},"python":{"code":"n = int(input());\nb = int(input());\ndef DecToAny(n,b):\n # Write your code here\nif __name__ == \"__main__\":\n res = DecToAny(n,b)\n print(res)"}},"points":10,"difficulty":"easy","sampleInput":"57\r\n 2","sampleOutput":"111001","questionVideo":"https://www.youtube.com/embed/N6TpoQemKF4","hints":[],"associated":[{"id":"0855543b-88de-4de4-829a-b60c2622dad0","name":"(d2ab) which number is not allowed while representing a number in binary form?","slug":"d2ab-which-number-is-not-allowed-while-representing-a-number-in-binary-form","type":4},{"id":"7e8f045c-4aa9-4cc2-b94a-68157ebc1cc5","name":"(d2ab) convert 2486 from decimal to base 8.","slug":"d2ab-convert-2486-from-decimal-to-base-8","type":4},{"id":"b74636a0-c267-44b1-ac43-7a6a888c68fb","name":"(d2ab) what will be the last digit when convert 4932 to octal?","slug":"d2ab-what-will-be-the-last-digit-when-convert-4932-to-octal","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"f10b54f1-0f44-408f-82d5-89c189f4ad57","name":"Function and Arrays","slug":"function-and-arrays","type":0},{"id":"078f18d4-97bb-4275-90f7-c49e333cac57","name":"Decimal To Any Base","slug":"decimal-to-any-base","type":1}],"next":{"id":"4002541f-c89f-4a48-995a-943435f09b8d","name":"Decimal To Any Base","type":3,"slug":"decimal-to-any-base"},"prev":{"id":"634f41c6-9454-4fe7-80f7-1c9d4f94b0c1","name":"Introduction to number system","type":0,"slug":"introduction-to-number-system"}}}`

# Decimal To Any Base

1. You are given a decimal number n. 2. You are given a base b. 3. You are required to convert the number n into its corresponding value in base b.

`{"id":"cda6687d-fc21-4aa2-9449-d2da391ddb68","name":"Decimal To Any Base","description":"1. You are given a decimal number n.\r\n2. You are given a base b.\r\n3. You are required to convert the number n into its corresponding value in base b.","inputFormat":"A number n\r\nA base b","outputFormat":"A number representing corresponding value of n in number system of base b","constraints":"0 &lt;= d &lt;= 512\r\n2 &lt;= b &lt;= 10","sampleCode":{"cpp":{"code":"#include<iostream>\nusing namespace std;\nint DecToAny(int n, int b){\n//write your code here\n}\nint main(){\n int n;\n int b;\n cin >> n;\n cin >> b;\n int res = DecToAny(n,b);\n cout << res << endl;\n}"},"java":{"code":"import java.util.*;\r\n \r\n public class Main{\r\n \r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int b = scn.nextInt();\r\n int dn = getValueInBase(n, b);\r\n System.out.println(dn);\r\n }\r\n \r\n public static int getValueInBase(int n, int b){\r\n // write code here\r\n }\r\n }"},"python":{"code":"n = int(input());\nb = int(input());\ndef DecToAny(n,b):\n # Write your code here\nif __name__ == \"__main__\":\n res = DecToAny(n,b)\n print(res)"}},"points":10,"difficulty":"easy","sampleInput":"57\r\n 2","sampleOutput":"111001","questionVideo":"https://www.youtube.com/embed/N6TpoQemKF4","hints":[],"associated":[{"id":"0855543b-88de-4de4-829a-b60c2622dad0","name":"(d2ab) which number is not allowed while representing a number in binary form?","slug":"d2ab-which-number-is-not-allowed-while-representing-a-number-in-binary-form","type":4},{"id":"7e8f045c-4aa9-4cc2-b94a-68157ebc1cc5","name":"(d2ab) convert 2486 from decimal to base 8.","slug":"d2ab-convert-2486-from-decimal-to-base-8","type":4},{"id":"b74636a0-c267-44b1-ac43-7a6a888c68fb","name":"(d2ab) what will be the last digit when convert 4932 to octal?","slug":"d2ab-what-will-be-the-last-digit-when-convert-4932-to-octal","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"f10b54f1-0f44-408f-82d5-89c189f4ad57","name":"Function and Arrays","slug":"function-and-arrays","type":0},{"id":"078f18d4-97bb-4275-90f7-c49e333cac57","name":"Decimal To Any Base","slug":"decimal-to-any-base","type":1}],"next":{"id":"4002541f-c89f-4a48-995a-943435f09b8d","name":"Decimal To Any Base","type":3,"slug":"decimal-to-any-base"},"prev":{"id":"634f41c6-9454-4fe7-80f7-1c9d4f94b0c1","name":"Introduction to number system","type":0,"slug":"introduction-to-number-system"}}}`

Editor

# Decimal To Any Base

easy

1. You are given a decimal number n. 2. You are given a base b. 3. You are required to convert the number n into its corresponding value in base b.

## Constraints

0 <= d <= 512 2 <= b <= 10

## Format

### Input

A number n A base b

### Output

A number representing corresponding value of n in number system of base b

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}57 2```

### Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}111001`

Question Video

Discussions

Show Discussion

Related Resources