fork download
  1. #include<stdio.h>
  2. #include<conio.h>
  3. int x, limit, b=0, a, y, real[100];
  4. void DecToBin(), DecToOct();
  5. void DecToHex(),BinToAll(), OctToAll(),HexToDec();
  6. char input[100];
  7. int bin[50], oct[50];
  8. char hex[50];
  9.  
  10. int main(void)
  11. {
  12. start:
  13. printf("\nEnter a number:");
  14. scanf("%s",input);
  15.  
  16. for(x=0;input[x]!='\0';x++)
  17. {}
  18. x--;
  19. //DECIMAL
  20. if(input[x]=='d')
  21. {
  22. limit=x-1;
  23. for(y=0;y<=limit;y++)
  24. {
  25. real[y]=input[y] -'0';
  26. b=b*10+(real[y]);
  27. }
  28. DecToHex();
  29. printf("\n");
  30. DecToBin();
  31. printf("\n");
  32. DecToOct();
  33.  
  34.  
  35. }
  36. //BINARY
  37. else if(input[x]=='b')
  38. {
  39. limit=x-1;
  40. for(y=0;y<=limit;y++)
  41. {
  42. real[y]=input[y] -'0' ;
  43. }
  44. for(a=0; a<limit;a++)
  45. {}
  46. BinToAll();
  47. }
  48. //OCTAL
  49. else if (input[x]=='o')
  50. {
  51. limit=x-1;
  52. for(y=0; y<=limit;y++)
  53. {
  54. real[y]=input[y]-'0';
  55. }
  56. for(a=0 ; a<limit; a++)
  57. {}
  58. OctToAll();
  59. }
  60. //HEXADECIMAL
  61. else if(input[x]=='h')
  62. {
  63. limit=x-1;
  64. for(y=0; y<=limit;y++)
  65. {
  66. real[y]=input[y];
  67. printf("%c", real[y]);
  68. }
  69. HexToDec();
  70.  
  71. }
  72. else if(input[0]=='e'&&input[1]=='x'&&input[2]=='i'&&input[3]=='t')
  73. {
  74. return 0;
  75. }
  76. else
  77. {
  78. printf("\n");
  79. }
  80. goto start;
  81. return 0;
  82. }
  83. //DECIMAL TO HEXADECIMAL
  84. void DecToHex(void)
  85. {
  86. int temp, x, y;
  87. temp=b;
  88. x=0;
  89. while(temp>0)
  90. {
  91. switch(temp%16)
  92. {
  93. case 10:
  94. real[x]='A';
  95. break;
  96. case 11:
  97. real[x]='B';
  98. break;
  99. case 12:
  100. real[x]='C';
  101. break;
  102. case 13:
  103. real[x]='D';
  104. break;
  105. case 14:
  106. real[x]='E';
  107. break;
  108. case 15:
  109. real[x]='F';
  110. break;
  111. default:
  112. real[x]=(temp%16)+0x30;
  113. }
  114. temp=temp/16;
  115. x++;
  116. }
  117.  
  118. for(y=(x-1);y>=0;y--)
  119. {
  120. printf("%c",real[y]);
  121. }
  122. printf("h");
  123. }
  124.  
  125. //DECIMAL TO BINARY
  126. void DecToBin()
  127. {
  128. int y=0, i,temp;
  129. int bin[50];
  130. for(temp=b;temp>0;y++)
  131. {
  132. bin[y]=temp%2;
  133. temp=temp/2;
  134. }
  135.  
  136. for ( i = y - 1; i > 0; i--)
  137. {
  138. printf("%i", bin[i]);
  139. }
  140. printf("%ib", bin[i]);
  141. }
  142. // DECIMAL TO OCTAL
  143. void DecToOct()
  144. {
  145. int y, i;
  146. int oct[100];
  147.  
  148. for(y=0; b>0; y++)
  149. {
  150. oct[y]=b%8;
  151. b=b/8;
  152. }
  153. for ( i = y - 1; i > 0; i--)
  154. {
  155. printf("%i", oct[i]);
  156. }
  157. printf("%io", oct[i]);
  158. }
  159.  
  160. //BINARY TO ALL
  161. void BinToAll()
  162. {
  163. //BINARY TO DECIMAL
  164. int pval, product, z, sum, temp ;
  165.  
  166. pval=1;
  167. z=0;
  168. while (a>=0)
  169. {
  170. product=real[a]*pval;
  171. sum=product+z;
  172. z=sum;
  173. pval=pval*2;
  174. a--;
  175. }
  176. printf("%i", sum);
  177. printf("d\n");
  178. temp=sum;
  179. //BINARY TO OCTAL
  180. for(x=0; sum>0; x++)
  181. {
  182. oct[x]=sum%8;
  183. sum=sum/8;
  184. }
  185.  
  186. for(y=(x-1);y>=0;y--)
  187. printf("%i", oct[y]);
  188. printf("o");
  189. //BINARY TO HEXADECIMAL
  190. x=0;
  191. while(temp>0)
  192. {
  193. switch(temp%16)
  194. {
  195.  
  196. case 10:
  197. hex[x]='A';
  198. break;
  199. case 11:
  200. hex[x]='B';
  201. break;
  202. case 12:
  203. hex[x]='C';
  204. break;
  205. case 13:
  206. hex[x]='D';
  207. break;
  208. case 14:
  209. hex[x]='E';
  210. break;
  211. case 15:
  212. hex[x]='F';
  213. break;
  214. default:
  215. hex[x]=(temp%16)+0x30;
  216. }
  217. temp=temp/16;
  218. x++;
  219.  
  220. }
  221. printf("\n");
  222. for(y=(x-1);y>=0;y--)
  223. printf("%c", hex[y]);
  224. printf("h");
  225.  
  226.  
  227. }
  228. //OCTAL TO ALL
  229. void OctToAll()
  230. {
  231. //OCTAL TO DECIMAL
  232. int pval, product, z, sum, temp ;
  233. pval=1;
  234. z=0;
  235. while (a>=0)
  236. {
  237. product=real[a]*pval;
  238. sum=product+z;
  239. z=sum;
  240. pval=pval*8;
  241. a--;
  242. }
  243. printf("%i", sum);
  244. printf("d\n");
  245. temp=sum;
  246. //OCTAL TO BINARY
  247. for(x=0; sum>0; x++)
  248. {
  249. oct[x]=sum%2;
  250. sum=sum/2;
  251. }
  252.  
  253. for(y=(x-1);y>=0;y--)
  254. printf("%i", oct[y]);
  255. printf("o");
  256. //OCTAL TO HEXADECIMAL
  257. x=0;
  258. while(temp>0)
  259. {
  260. switch(temp%16)
  261. {
  262.  
  263. case 10:
  264. hex[x]='A';
  265. break;
  266. case 11:
  267. hex[x]='B';
  268. break;
  269. case 12:
  270. hex[x]='C';
  271. break;
  272. case 13:
  273. hex[x]='D';
  274. break;
  275. case 14:
  276. hex[x]='E';
  277. break;
  278. case 15:
  279. hex[x]='F';
  280. break;
  281. default:
  282. hex[x]=(temp%16)+0x30;
  283. }
  284. temp=temp/16;
  285. x++;
  286.  
  287. }
  288. printf("\n");
  289. for(y=(x-1);y>=0;y--)
  290. printf("%c", hex[y]);
  291. printf("h");
  292. }
  293.  
  294. void HexToDec();
  295. {
  296. int temp, x,y;
  297. x=0;
  298. temp=b;
  299. while (temp>0)
  300. {
  301. switch(temp)
  302. }
  303. }
  304.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:2:18: fatal error: conio.h: No such file or directory
 #include<conio.h>
                  ^
compilation terminated.
stdout
Standard output is empty