Advertisement
Radoan_Ahmed

Untitled

Aug 3rd, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.98 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3.  
  4. int  octaldecimal(int c)
  5. {
  6.    int temp=0,i=0,mod;
  7.    while(c!=0)
  8.     {
  9.         mod=c%10;
  10.         temp=temp+mod*pow(8,i);
  11.         c=c/10;
  12.         i++;
  13.     }
  14.     return temp;
  15. }
  16.  
  17.  
  18. int  decimal(int c)
  19. {
  20.    int temp=0,i=0,mod;
  21.    while(c!=0)
  22.     {
  23.         mod=c%10;
  24.         temp=temp+mod*pow(2,i);
  25.         c=c/10;
  26.         i++;
  27.     }
  28.     return temp;
  29. }
  30.  
  31. void hexadecimal(int a)
  32. {
  33.   int  i=0,count=0,arr[1000];
  34.   while(a!=0)
  35.     {
  36.         arr[i]=a%16;
  37.         count+=1;
  38.         a=a/16;
  39.         if(arr[i]<10)
  40.         {
  41.             arr[i]=48+arr[i];
  42.         }
  43.         else if(arr[i]>=10)
  44.         {
  45.             arr[i]=55+arr[i];
  46.         }
  47.         i++;
  48.  
  49.     }
  50.     for(i=count-1;i>=0;i--)
  51.     {
  52.         printf("%c",arr[i]);
  53.     }
  54. }
  55.  
  56.  
  57. void binary(int c)
  58. {
  59.     int count=0,i=0,arr[1000];
  60.      while(c!=0)
  61.     {
  62.         arr[i]=c%2;
  63.         count+=1;
  64.         c=c/2;
  65.         i++;
  66.     }
  67.     for(i=count-1;i>=0;i--)
  68.     {
  69.         printf("%d",arr[i]);
  70.     }
  71. }
  72.  
  73.  
  74. int main()
  75. {
  76.     int a,b,c,x;
  77.     printf("Enter 0 for goto menu:\n");
  78.     printf("*************************\n");
  79.     printf("*************************\n");
  80.     scanf("%d",&a);
  81.     printf("*************************\n");
  82.     printf("*************************\n");
  83.  
  84.  
  85.  
  86.     if(a==0)
  87.     {
  88.         printf("//Enter 1   for Decimal to Binary      :\t      //Enter 2   for Octal to Binary       :\n");
  89.         printf("//Enter 3   for Decimal to Octal       :\t      //Enter 4   for Octal to Decimal      :\n");
  90.         printf("//Enter 5   for Decimal to Hexadesimal :\t      //Enter 6   for Octal to Hexadesimal  :\n");
  91.         printf("                                        \t                                             \n");
  92.         printf("                                        \t                                             \n");
  93.         printf("//Enter 7   for Binary  to Decimal     :\t      //Enter 8   for Hexadesimal to Decimal:\n");
  94.         printf("//Enter 9   for Binary  to Octal       :\t      //Enter 10  for Hexadesimal to Binary :\n");
  95.         printf("//Enter 11  for Binary  to Hexadesimal :\t      //Enter 12  for Hexadesimal to Octal  :\n");
  96.         printf("                                                                                       \n");
  97.  
  98.  
  99.         printf("***");
  100.  
  101.         scanf("%d",&b);
  102.  
  103.         if(b==1)
  104.         {
  105.             printf("Enter Decimal number:\n");
  106.             scanf("%d",&c);
  107.             printf("The Binary from of %d is :",c);
  108.             binary(c);
  109.         }
  110.         else if(b==2)
  111.         {
  112.             scanf("%d",&c);
  113.             x=octaldecimal(c);
  114.             printf("The Binary from of Octal number is ");
  115.             binary(x);
  116.         }
  117.  
  118.         else if(b==3)
  119.         {
  120.             printf("Enter Decimal number:\n");
  121.             scanf("%d",&c);
  122.             printf("The Octal from of Decimal number is %o\n",c);
  123.         }
  124.  
  125.         else if(b==4)
  126.         {
  127.             scanf("%d",&c);
  128.             x=octaldecimal(c);
  129.             printf("The Decimal from of Octal number is %d",x);
  130.         }
  131.  
  132.         else if(b==5)
  133.         {
  134.             printf("Enter Decimal number:\n");
  135.             scanf("%d",&c);
  136.             hexadecimal(c);
  137.         }
  138.  
  139.         else if(b==6)
  140.         {
  141.             scanf("%d",&c);
  142.             x=octaldecimal(c);
  143.             printf("The Hexadecimal from of Octal number is ");
  144.             hexadecimal(x);
  145.  
  146.         }
  147.  
  148.         else if(b==7)
  149.         {
  150.  
  151.              scanf("%d",&c);
  152.              printf("The Decimal from of Binary number is %d\n",decimal(c));
  153.  
  154.         }
  155.  
  156.         else if(b==8)
  157.         {
  158.  
  159.         }
  160.         else if(b==9)
  161.         {
  162.             scanf("%d",&c);
  163.             x=decimal(c);
  164.             printf("The Octal from of Binary number is %o\n",x);
  165.         }
  166.         else if(b==11)
  167.         {
  168.             scanf("%d",&c);
  169.             x=decimal(c);
  170.             printf("The Hexadecimal from of Binary number is ");
  171.             hexadecimal(x);
  172.         }
  173.  
  174.  
  175.     }
  176.  
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement