harish reddy

harish reddy

  • NA
  • 162
  • 33.5k

Reverse a number - Decimal to Octal

Jan 3 2018 5:42 AM
Write a program in C# Sharp to convert a decimal number into octal without using an array.
 
I have done the proram til here:
 
int decimalnumber = int.Parse(Console.ReadLine());
int remainder;
for (int i = 0; i < 3; i++)
{
remainder = decimalnumber % 8;
int quotient = decimalnumber / 8;
decimalnumber = quotient;
Console.Write(remainder);
}
 
when i execute the program and give input as  117 for example, i am getting ouput as 561. However, i should be getting 165. Pls let me know how i can reverse them with out using array. 

Answers (5)