WAP to convert Decimal to Octal number System
This C Program
Converts the given Decimal to Octal. Octal is a numbering system that uses
eight digits, 0 to 7, arranged in a series of columns to represent all
numerical quantities. Each column or place value has a weighted value of 1, 8,
64, 512, and so on ranging from right to left. Decimal is a term that describes
the base-10 number system commonly used by lay people in the developed world.
Here is source code of
the C program to Convert Decimal to Octal. The C program is successfully
compiled and run on a Linux system. The program output is also shown below.
1. /*
2. * C program to Convert Decimal to Octal
3. */
4. #include <stdio.h>
5.
6. int main()
7. {
8. long
decimalnum, remainder,
quotient;
9. int
octalNumber[100], i = 1, j;
10.
11. printf("Enter
the decimal number: ");
12. scanf("%ld",
&decimalnum);
13. quotient =
decimalnum;
14. while
(quotient != 0)
15. {
16. octalNumber[i++] =
quotient % 8;
17. quotient =
quotient / 8;
18. }
19. printf("Equivalent
octal value of decimal no %d: ", decimalnum);
20. for (j = i - 1; j > 0; j--)
21. printf("%d",
octalNumber[j]);
22. return
0;
23. }
Output:
$ cc
pgm11.c
$ a.out
Enter the decimal number: 68
Equivalent octal value of decimal no 68: 104
Comments
Post a Comment