Write a Program to Display Factors of a Number. For Example:
Output :
Enter a positive integer: 60
Factors of 60 are: 1 2 3 4 5 6 12 15 20 30 60
int n;
Console.Write("Enter a Positive Number ");
n = Convert.ToInt32(Console.ReadLine());
Console.Write("Factors of {0} are :",n);
for (int i = 1; i < n; ++i)
{
if (n % i==0)
{
Console.Write(" "+i);
}
}
0 comments:
Post a Comment