P14 To print all divisors of a given number



    class Program
    {
        static void Main(string[] args)
        {
            int n;
            Console.Write("Enter the number : ");
            n = int.Parse(Console.ReadLine());
            Console.WriteLine("The divisors are ");
            for (int i = 1; i <= n; i++)
            {
                if (n % i == 0)
                {
                    Console.WriteLine(i);
                }
            }
            Console.ReadLine();
        }
    }

Output :



No comments:

Post a Comment