Tuesday, 5 January 2016

converting decimal number to binary number program in c#

using System;
using System.Collections.Generic;


namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = int.Parse(Console.ReadLine());
            List<int> list = new List<int>();
            Console.Write("1");
            while ( x / 2 >=1) {
                if (x % 2 == 1)
                {
                    list.Add(1);
                }
                else {
                    list.Add(0);
                }
                x = x / 2;

            }
            for (int i = list.Count-1; i >=0; i--) // Loop with for.
            {
                Console.Write(list[i]);
            }

                Console.ReadKey();
        }
    }
}

christmas tree program in c#

using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
         
            for (int x=1; x < 25;x++ )
            {
                int y = 0;
                int z = 25;
                while (z > x)
                {
                    Console.Write(" ");
                    z--;
                };
                while (y < x * 2)
                {                  
                    Console.Write("*");
                    y++;            
                };
                    Console.Write("\n");
            };
            for (int x = 1; x < 7; x++)
            {
                int y = 0;
                while (y < 24)
                {
                    Console.Write(" ");
                    y++;
                };

                Console.WriteLine("****");
            };
                    Console.Read();
        }
    }
}