Saturday, 29 August 2015

decimal to octal converter




C code for decimal to octal converter



#include<stdio.h>
int main(){
  long int decimalNumber,remainder,quotient;
  int octalNumber[100],i=1,j;
  printf("Enter any decimal number: ");
  scanf("%ld",&decimalNumber);
  quotient = decimalNumber;
  while(quotient!=0){
      octalNumber[i++]= quotient % 8;
      quotient = quotient / 8;
  }
  printf("Equivalent octal value of decimal number %d: ",decimalNumber);
  for(j = i -1 ;j> 0;j--)
      printf("%d",octalNumber[j]);
  return 0;
}
Sample output:
Enter any decimal number: 50
Equivalent octal value of decimal number 50: 62
2. Easy way to convert decimal number to octal number in c

#include<stdio.h>
int main(){
  long int decimalNumber;
  printf("Enter any decimal number : ");
  scanf("%d",&decimalNumber);
  printf("Equivalent octal number is: %o",decimalNumber);
  return 0;
}
Sample output:
Enter any decimal number: 25
Equivalent octal number is: 31

Leave a Reply

 
 

Labels

Blog Archive