fork download
  1. #include <stdio.h>
  2. enum state {success,fail,quit};
  3. int status = fail;
  4.  
  5. int main(void)
  6. {
  7. int n;
  8. char t;
  9. do
  10. {
  11. printf("Enter a number between 0 and 32767: ");
  12.  
  13. if(scanf("%d", &n) == 1 && ((n > 0) && (n < 32767)) )
  14. status = success;
  15. else
  16. while((t=getchar()) !='\n' && t !=EOF) ;
  17. }while (status == fail);
  18. if (status == success)
  19. {
  20.  
  21. int oct1, oct2, oct3, oct4, oct5;
  22.  
  23. oct1 = ((((n / 8) / 8) / 8) / 8) % 8;
  24. oct2 = (((n / 8) / 8) / 8) % 8;
  25. oct3 = ((n / 8) / 8) % 8;
  26. oct4 = (n / 8) % 8;
  27. oct5 = n % 8;
  28.  
  29. printf("In octal, your number is: %d%d%d%d%d\n", oct1, oct2, oct3, oct4, oct5);
  30. return 0;
  31. }
  32. }
Success #stdin #stdout 0s 2296KB
stdin
a
b
122
stdout
Enter a number between 0 and 32767: Enter a number between 0 and 32767: Enter a number between 0 and 32767: In octal, your number is: 00172