Author : Rahul

Write a program to print the factor of a number


Program

using System;

namespace ProgrammingQuestion
{
 class Program
 {
   static void Main(string[] args)
   {
     //Variable Declaration
     string numberVal;
     int number;
     
     //User Input
     Console.Write("Enter Number:");
     numberVal = Console.ReadLine();
     number = Convert.ToInt32(numberVal);

     //Factorial Logic and Print Result
     Console.WriteLine($"Factorial of the Number {number}:");
     Console.Write("1 , ");
     for (int i = 2; i <= number / 2; i++)
     {
       if (number % i == 0)
       {
         Console.Write($" {i} ,");
       }
     }
     Console.Write($" {number}");
     Console.Read();
   }
 }
}

Output

Enter Number:48
Factorial of the Number 48:
1 ,  2 , 3 , 4 , 6 , 8 , 12 , 16 , 24 , 48