Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# program to convert decimal to Octal number
Set the decimal number −
int decVal = 40;
Now take a variable and set the decVal in it. Find the remainder with 8 since octal has base-8 number system and evaluate it in a loop like the following code snippet.
while (quot != 0) {
octalVal[i++] = quot % 8;
quot = quot / 8;
}
Example
You can try to run the following code to convert decimal to octal number.
using System;
class Demo {
public static void Main() {
int decVal, quot, i = 1, j;
int[] octalVal = new int[80];
decVal = 40;
quot = decVal;
Console.WriteLine("Decimal Number:{0}",decVal);
while (quot!= 0) {
octalVal[i++] = quot % 8;
quot = quot / 8;
}
Console.Write("Octal Number: ");
for (j = i - 1; j > 0; j--)
Console.Write(octalVal[j]);
Console.Read();
}
}
Output
Decimal Number:40 Octal Number: 50
Advertisements