#include <stdio.h>
int main(void)
{
unsigned int value;
printf("Input octal value: ");
scanf("%o", &value);
printf("value in octal format: %o\n", value);
printf("value in decimal format: %d\n", value);
//testing with invalid value
printf("Input octal value: ");
scanf("%o", &value);
printf("value in octal format: %o\n", value);
printf("value in decimal format: %d\n", value);
return 0;
}
Output
Input octal value: 127
value in octal format: 127
value in decimal format: 87
Input octal value: 1278
value in octal format: 127
value in decimal format: 87
Explanation:
See the second input and its result, the input value is 1278 and the accepted value is 127 because 8 is not a valid octal digit. Octal numbers have only 8 digits which are 0, 1, 2, 3, 4, 5, 6 and 7.
Program:
Output
Explanation:
See the second input and its result, the input value is 1278 and the accepted value is 127 because 8 is not a valid octal digit. Octal numbers have only 8 digits which are 0, 1, 2, 3, 4, 5, 6 and 7.
need an explanation for this answer? contact us directly to get an explanation for this answer