Facebook
From faszom, 2 Years ago, written in C#.
Embed
Download Paste or View Raw
Hits: 77
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. using System.Threading;
  8.  
  9. namespace ConsoleApp3
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             Console.Write("Irjon be egy szamot : ");
  16.             int szam = int.Parse(Console.ReadLine());
  17.             int szamt = szam;
  18.             int db = 0;
  19.             do
  20.             {
  21.                 szamt = szamt / 2;
  22.                 db++;
  23.  
  24.             } while (szamt != 1);
  25.             db++;
  26.             int[] tomb = new int[db];
  27.             int i = 0;
  28.             do
  29.             {
  30.  
  31.                 if (szam >= 1)
  32.                 {
  33.                     if (szam % 2 == 0)
  34.                     {
  35.                         tomb[i] = 0;
  36.                     }
  37.                     else if (szam % 2 == 1)
  38.                     {
  39.                         tomb[i] = 1;
  40.                     }
  41.                     szam = szam / 2;
  42.                     i++;
  43.                 }
  44.             } while (szam > 0.99);
  45.  
  46.             Console.Write("\n\nA szam: ");
  47.  
  48.             for (int l = tomb.Length - 1; l >= 0; l--)
  49.             {
  50.                 Console.Write(tomb[l]);
  51.             }
  52.  
  53.             //komplementer
  54.             for (int l = tomb.Length - 1; l >= 0; l--)
  55.             {
  56.                 if (tomb[l] == 1)
  57.                 {
  58.                     tomb[l] = 0;
  59.                 }
  60.                 else if (tomb[l] == 0)
  61.                 {
  62.                     tomb[l] = 1;
  63.                 }
  64.             }
  65.  
  66.             Console.Write("\n\nkomplementer: ");
  67.  
  68.             for (int l = tomb.Length - 1; l >= 0; l--)
  69.             {
  70.                 Console.Write(tomb[l]);
  71.             }
  72.  
  73.             Console.ReadKey();
  74.         }
  75.     }
  76. }