C Program to Convert Decimal to Octal

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    long int decimal_num, rem, quotient;
    int i=1, j, octal_num[100];
    printf("\n Enter any decimal number : ");
    scanf("%ld",&decimal_num);
    quotient=decimal_num;
    while(quotient!=0)
    {
        octal_num[i++]=quotient%8;
        quotient=quotient/8;
    }
    printf("\n Equivalent octal value of %d is : \n",decimal_num);
    for(j=i-1; j>0; j--)/*Array in reverse order*/
    {
        printf("\t %d",octal_num[j]);
    }
    getch();
}

Run1:
Run2:


No comments:

Post a Comment

100 C Programs with Code and Output

Program 1: C Program To Read Two Numbers And Print The Sum Of Given Two Numbers. Program 2: C Program To Read Three Numbers And Prin...