C Program to Convert Decimal to Octal




c programming
c programming

The base 8 number system is known as octal we’ll look at number conversions.
C Program to Convert Decimal to Octal

/**********************************************************************
Convert Decimal to Octal in C Language
 **********************************************************************/
#include<stdio.h>
#include<conio.h>
void main()
{
  long int n,n1,m=1,rem,ans=0;
  printf("\nEnter Your Decimal No : ");
  scanf("%ld",&n);

  n1=n;
  while(n>0)
    {
      rem=n%8;
      ans=(rem*m)+ans;
      n=n/8;
      m=m*10;
    }

  printf("\nYour Decimal No is : %ld",n1);
  printf("\nConvert into Octal No is : %ld",ans);
}

/*
OUTPUT:

Enter Your Decimal No : 16

Your Decimal No is : 16
Convert into Octal No is : 20P

*/

 


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com





Be the first to comment

Leave a Reply

Your email address will not be published.


*