Simon is studying B.Tech.-Mechanical Engineering. He’s going to attend a computer science-based subject exam this semester. Due to the less preparation in the previous monthly tests, his internal mark decreased. His computer science Professor made an offer one more chance to boost up his internal marks.
Professor assigns a program to Simon for the internal mark bootup. So Simon wants to solve Questions of conversion from Binary to octal.
can you help him in solving Questions by creating a function for the conversion of binary to octal?
Explanation:
Consider the binary number 1111 which has to be converted to octal.
Divide the binary number into groups of three from right to left. 1111 can be grouped as 001 111 Now, find the octal number for each group.
Three-bit binary numbers from (000 to 111) have equal decimal and octal representations.
Hence, the octal numbers for binary numbers in the range (000 to 111) are same as that of the decimal numbers. The octal number of 001 is 1 and 111 is 7. The octal equivalent of 1111 is 17.
Input:
Input as an integer (010101) from the user
Output:
Print the “octal number” value.
#include <stdio.h> #include <math.h> int convertBinarytoOctal(long long binaryNumber); int main() { int long n; scanf("%ld",&n); printf("%d\n",convertBinarytoOctal(n)); return 0; } int convertBinarytoOctal(long long binaryNumber) { int oct=0,dec=0,i=0; while(binaryNumber!=0){ dec+=(binaryNumber%10)*pow(2,i); ++i; binaryNumber/=10; } i=1; while(dec!=0){ oct+=(dec%8)*i; dec/=8; i*=10; } return oct; }
INPUT_1:
101001
OUTPUT:
51
INPUT_2:
101110
OUTPUT:
56
INPUT_3:
111111
OUTPUT:
77
INPUT_4:
110011
OUTPUT:
63
ILLUSTRATION
![](http://www.fcukthecode.com/wp-content/uploads/2022/01/Screenshot-from-2022-01-05-12-08-51.png)
Morae Q!
- Conversion of days into year, weeks and days.
- Find if the number is a perfect number or not.
- Compute conversion of Binary to Octal.
- Return the sum of digits in a number.
- Find if a word exists or not in a sentence.
- Convert Numbers into Words.
- Read a word if it consists only of the letters known.
- Check if the string is a dynamic string or not.
- Convert all Uppercase letters to Lowercase and vice-versa.
- Change the string such that there are no matching adjacent characters.
- Find the number of sub-strings which start and end both in 1.
- Find the start and end index of unsorted sub-array.
- Find the maximum number of pairs that can be formed.
- Figure out the number of bubbly words present.
- Check if a string is lapindrome or not even with a middle character.
- Seating layout in a triangular shaped class according to the number of rows.
- Find and Sort a sub-array which makes whole array sorted.
- Seating layout according to the number of rows.
- Find the final states of the bulbs.
- Check if reversing sub array makes the array sorted.