Showing posts with label C# Programming. Show all posts
Showing posts with label C# Programming. Show all posts

Friday 17 March 2017

Write a Program to Display Factors of a Number.

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);

}
}

Copyright @ 2015 Computer Tricks.