Q:

C program to convert number from Decimal to Octal

0

C program to convert number from Decimal to Octal

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Decimal to Octal Conversion using C program

/*C program to convert number from decimal to octal*/

#include <stdio.h>

int main()
{
    int number, cnt, i;
    int oct[32];

    printf("Enter decimal number: ");
    scanf("%d", &number);

    cnt = 0; /*initialize index to zero*/
    while (number > 0) {
        oct[cnt] = number % 8;
        number = number / 8;
        cnt++;
    }

    /*print value in reverse order*/
    printf("Octal value is: ");
    for (i = (cnt - 1); i >= 0; i--)
        printf("%d", oct[i]);

    return 0;
}

Output:

    Enter decimal number: 545
    Octal value is: 1041

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C program to convert number from Decimal to Hexade... >>
<< C program to convert number from Decimal to Binary...