Created
January 27, 2015 18:41
-
-
Save ahmedeshaan/eafcb34c120589f3dca6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int main() | |
{ | |
int bin = 0; | |
printf("Please Enter your positive binary number:"); | |
scanf("%ld",&bin); | |
int main_mod_output; | |
int sub_modulous_output; | |
int sub_mod_cod_out=0; | |
int sub_mod_next_con = 0; | |
int sub_mod_final_output = 0; | |
int final_output=0; | |
int array_input[10]; | |
int i = 1; | |
while(bin!=0){ | |
// For chuking input into 3 digit | |
main_mod_output = bin % 1000; | |
// Assign the value into separate variable | |
sub_modulous_output = main_mod_output; | |
// This loop for looping round 3 digits | |
while(sub_modulous_output){ | |
if(sub_mod_cod_out==0){ | |
// Set 1 for exponet first value 1 | |
sub_mod_cod_out = 1; | |
}else{ | |
// Exponet other with 2 | |
sub_mod_cod_out *=2; | |
} | |
// Create a new variable to store modulous value | |
sub_mod_next_con = sub_modulous_output % 10; | |
// Create a new variable to store the multiplication of modulous and exponent outpurs | |
sub_mod_final_output = sub_mod_next_con * sub_mod_cod_out; | |
// Create a new variable to store indivual numbers, I get after ching nth value into 3 digits | |
final_output += sub_mod_final_output; | |
// To minimize the loop count donw | |
sub_modulous_output /= 10; | |
} | |
// Store indivisual digits in arrage | |
array_input[i] = final_output; | |
i++; | |
// Made both 2 variable zero, only to start again | |
sub_mod_cod_out = 0; | |
final_output = 0; | |
//printf("%d",output); | |
bin /= 1000; | |
} | |
int j=0; | |
// Combile out put indivisual digits to print final octal output | |
for(j=i-1;j>=1;j--){ | |
printf("%d",array_input[j]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment