Facebook
From Trivial Ibis, 2 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 125
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main()
  5. {
  6.     printf("Enter 3 binaries to convert them to decimals \n");
  7.     for(int i = 0 ; i < 3 ; i++)
  8.     {
  9.         long long bin = 0, dec = 0;
  10.         scanf("%lld", &bin);
  11.         long long trash = bin , amount = 0;
  12.         while(trash>=1)
  13.         {
  14.             trash = trash / 10;          ///calculatinng the length of the number
  15.             amount++;
  16.         }
  17.         for(int i = 0 ; i < amount ; i++)
  18.         {
  19.             int num = 0;
  20.             num = bin % 10;
  21.             bin = bin / 10;                 ///converting in line power method
  22.             dec = dec + pow(2 , i) * num;
  23.         }
  24.         printf("%lld \n", dec);
  25.     }
  26.     printf("Enter 3 decimals to convert them to binaries \n");
  27.     for(int i = 0 ; i < 3; i++)
  28.     {
  29.         long long dec = 0 , bin = 0;
  30.         scanf("%lld", &dec);
  31.         int lvl = 0;
  32.         while(dec > 0)
  33.         {
  34.             bin = bin + dec % 2 * pow(10, lvl);      ///converting in column method
  35.             dec = dec / 2;
  36.             lvl++;
  37.         }
  38.         printf("%lld \n", bin);
  39.     }
  40.     printf("Enter 3 heximals to convert them into decimals \n");
  41.     for(int i = 0 ; i < 3 ; i++)
  42.     {
  43.         long long num = 0;
  44.         scanf("%x", &num);                     ///using C language advantages to convert the number
  45.         printf("%d \n", num);
  46.     }
  47.     printf("Enter 3 decimals to convert them into heximals \n");
  48.     for(int i = 0 ; i < 3 ; i++)
  49.     {
  50.         long long num = 0;
  51.         scanf("%d", &num);                     ///using C language advantages to convert the number
  52.         printf("%x \n", num);
  53.     }
  54.  
  55.  
  56.     return 0;
  57. }
  58.  

Replies to Untitled rss

Title Name Language When
Re: Untitled Eratic Cheetah text 2 Years ago.