# Program to convert decimal to octal using while loop

### Code:

#include <stdio.h>
int
main ()
{
int rem, number,sem=1,octal=0;
printf ("Enter the Decimal Number:");
scanf ("%d",&number);

while(number !=0)
{
octal=octal+(number%8)*sem;
number=number/8;
sem=sem*10;
}
printf (" Octal Number is %d",octal);
return 0;
}

Input/Output:
Enter the Decimal Number:35
Octal Number is 43

### Code:

#include <iostream>
using namespace std;
int
main ()
{
int rem, number,sem=1,octal=0;
cout<<"Enter the Decimal Number:";
cin>>number;

while(number !=0)
{
octal=octal+(number%8)*sem;
number=number/8;
sem=sem*10;
}

cout<<"Octal Number is "<<octal;
}

Input/Output:
Enter the Decimal Number:78
Octal Number is 116

### Code:

import java.util.Scanner;
public class DecimalToOctal {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int rem, number,sem=1,octal=0;
System.out.println("Enter the Decimal Number:");
number=cs.nextInt();

while(number !=0)
{
octal=octal+(number%8)*sem;
number=number/8;
sem=sem*10;
}

System.out.println("Octal Number is "+octal);
cs.close();
}
}

Input/Output:
Enter the Decimal Number:
89
Octal Number is 131

### Code:

sem=1
octal=0
print("Enter the Decimal Number:")
number=int(input())
while(number !=0):
octal=octal+(number%8)*sem
number=number//8
sem=int(sem*10)

print("Octal Number is ",octal)

Input/Output:
Enter the Decimal Number:
9
Octal Number is  11