File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -4,3 +4,4 @@ Ravi Kant Garg (garg-ravi24)
4
4
Sumit Gupta(Invincisumit)
5
5
Shifali Gupta (Gupta-shifali)
6
6
Mohit Sharma (ms10398)
7
+ Harshit Luthra (sachincool)
Original file line number Diff line number Diff line change
1
+ fun main (args : Array <String >) //Main function
2
+ {
3
+ val decimal = 18 // Let's Take a number for Example
4
+ val octal = DecimalToOctal (decimal)
5
+ println (" $decimal in decimal = $octal in octal" ) // calling decimal and octal inside ""
6
+ }
7
+
8
+ fun DecimalToOctal (decimal : Int ): Int // Our main function which converts decimal to octal
9
+ {
10
+ var decimal = decimal
11
+ var octalNumber = 0
12
+ var i = 1
13
+
14
+ while (decimal != 0 ) {
15
+ octalNumber + = decimal % 8 * i
16
+ decimal / = 8
17
+ i * = 10
18
+ }
19
+
20
+ return octalNumber
21
+ }
Original file line number Diff line number Diff line change
1
+ fun main (args : Array <String >) //Main Function
2
+ {
3
+ val octal = 18
4
+ val decimal = OctalToDecimal (octal)
5
+ println (" $octal in octal = $decimal in decimal" ) // This is the method to print variable inside Quotes
6
+ }
7
+
8
+ fun OctalToDecimal (octal : Int ): Int // Conversion Function With Return type Int
9
+ {
10
+ var octal = octal
11
+ var decimalNumber = 0
12
+ var i = 0
13
+
14
+ while (octal != 0 ) {
15
+ decimalNumber + = (octal % 10 * Math .pow(8 ,i).toInt()) // Easy Peasy right ? We need to Convert The Math.pow to Integer.
16
+ ++ i
17
+ octal / = 10
18
+ }
19
+
20
+ return decimalNumber // No Semicolon Weeeeee!!
21
+ }
You can’t perform that action at this time.
0 commit comments