P6 To find whether the given number is a perfect square or not

    class Program
    {
        static void Main(string[] args)
        {
            int n;
            bool flag = false;
            Console.Write("Enter the number : ");
            n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n / 2; i++)
            {
                if ((i * i) == n)
                {
                    flag = true;
                }
            }
            if (flag)
            {
                Console.WriteLine(n + " is a perfect square");
            }
            else
            {
                Console.WriteLine(n + " is not a perfect square");
            }
            Console.ReadLine();
        }
    }

Output 1 :
Output 2 :

No comments:

Post a Comment