C program to convert Decimal number to Octal number:
If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().
#include<stdio.h> #include<math.h> // Function For Calculating OCTAL Number void dec_oct(long int num) { long int rem[50],i=0,length=0; while(num>0) { rem[i]=num%8; num=num/8; i++; length++; } printf("Octal number : "); //Printing Octal Number for(i=length-1;i>=0;i--) printf("%ld",rem[i]); } //Main Function main() { long int num; printf("Enter the decimal number : "); scanf("%ld",&num); dec_oct(num); //Function Call }
OUTPUT:
Enter the decimal number : 45 Octal number : 55