Sunday, 1 September 2013

power of 2 ?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace powerof2
{
    class Program
    {
       static void Main(string[] args)
       {
           int number, i=1,dup,flag=0;
           Console.WriteLine("enter the number ");
           number = Int32.Parse(Console.ReadLine());
           while (i <= 1000)
           {
               dup = i * 2;
               i = dup;
               if (dup == number)
               {
                
                   flag = 1;
                  
               }


           }

           if (flag == 1)
           {
               Console.WriteLine("no is power of 2");
           }
           else
           {
               Console.WriteLine("no is not power of 2");
           }
           Console.WriteLine();
       }
      
    }
}

No comments:

Post a Comment