programming-examples/c/Basic/C program to Convert Decimal to Octal.c

22 lines
562 B
C
Raw Normal View History

2019-11-18 14:44:36 +01:00
/*
* C program to Convert Decimal to Octal
*/
#include <stdio.h>
int main()
{
long decimalnum, remainder, quotient;
int octalNumber[100], i = 1, j;
printf("Enter the decimal number: ");
scanf("%ld", &decimalnum);
quotient = decimalnum;
while (quotient != 0)
{
octalNumber[i++] = quotient % 8;
quotient = quotient / 8;
}
printf("Equivalent octal value of decimal no %d: ", decimalnum);
for (j = i - 1; j > 0; j--)
printf("%d", octalNumber[j]);
return 0;
}