Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Lizard Squad -Mafia Write a program that reads an integer between 0 and 32767 an

ID: 638602 • Letter: L

Question

Lizard Squad

-Mafia

Write a program that reads an integer between 0 and 32767 and displays it as a 5-digit octal (base 8) number. The output should display 5 digits even if fewer are needed. Your code must be in the downloaded file octal.c. Your output should match the example below (except that the input will be different for other executions!) User input is underlined. Enter a number between 0 and 32767: 1953 In octal, your number is: 03641 Hint: You can obtain the octal digits of a number n from right to left by applications of % and /. The low order digit is n%8; and n/8 is n with the rightmost octal digit removed. Note: printf is capable of automatically displaying and integer in octal (explained later). Do not use this! You must use the % and / method described above.

Explanation / Answer

#include <stdio.h>

int decimal_octal(int n){ /* Function to convert decimal to octal */
   int rem, i=1, octal=0;
   while (n!=0){
       rem=n%8;
       n/=8;
       octal+=rem*i;
       i*=10;
   }
   return octal;
}


int main(void) {
   int n;
   printf("%s","Enter a number between 0 and 32767 : ");
   scanf("%d",&n);
   printf("%d ", decimal_octal(n));
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote