2017-09-29 19:38:15 +03:00
|
|
|
/*****Decimal to octal conversion*******************/
|
|
|
|
#include <stdio.h>
|
|
|
|
void decimal2Octal(long decimalnum);
|
2020-05-29 23:23:24 +03:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2017-09-29 19:38:15 +03:00
|
|
|
long decimalnum;
|
|
|
|
|
|
|
|
printf("Enter the decimal number: ");
|
2020-05-29 23:23:24 +03:00
|
|
|
scanf("%ld", &decimalnum);
|
|
|
|
|
2017-09-29 19:38:15 +03:00
|
|
|
decimal2Octal(decimalnum);
|
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
return 0;
|
2017-09-29 19:38:15 +03:00
|
|
|
}
|
2020-05-29 23:23:24 +03:00
|
|
|
|
|
|
|
/********function for convert decimal numbers to octal numbers************/
|
|
|
|
void decimal2Octal(long decimalnum)
|
|
|
|
{
|
|
|
|
long remainder, quotient;
|
2017-09-29 19:38:15 +03:00
|
|
|
|
|
|
|
int octalNumber[100], i = 1, j;
|
|
|
|
quotient = decimalnum;
|
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
while (quotient != 0)
|
|
|
|
{
|
|
|
|
octalNumber[i++] = quotient % 8;
|
2017-09-29 19:38:15 +03:00
|
|
|
|
|
|
|
quotient = quotient / 8;
|
2020-05-29 23:23:24 +03:00
|
|
|
}
|
2017-09-29 19:38:15 +03:00
|
|
|
|
2020-06-28 18:25:37 +03:00
|
|
|
for (j = i - 1; j > 0; j--) printf("%d", octalNumber[j]);
|
2017-09-29 19:38:15 +03:00
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
printf("\n");
|
2017-09-29 19:38:15 +03:00
|
|
|
}
|