Users Online

· Guests Online: 118

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C# Program to Find the Factors of the Given Number

C# Program to Find the Factors of the Given Number

 

 

This is a C# Program to display the factors of the entered number.

Problem Description

This C# Program Displays the Factors of the Entered Number.

Problem Solution

The factors of a number are all those numbers that can divide evenly into the number with no remainder.

Program/Source Code

Here is source code of the C# program which checks a given integer is odd or even. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 * C# Program to Display the Factors of the Entered Number
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace Program
{
    class Program
    {
        static void Main(string[] args)
        {
            int num, x;
            Console.WriteLine("Enter the Number ");
            num = int.Parse(Console.ReadLine());
            Console.WriteLine("The Factors are : ");
            for (x = 1; x <= num; x++)
            {
                if (num % x == 0)
                {
                    Console.WriteLine(x);
                }
            }
            Console.ReadLine();
 
        }
    }
}
Program Explanation

In this C# program, we are reading the number using ‘num’ variable. Using for loop compute the factors of the entered number, the factors of a number are all those numbers that can divide evenly into the number with no remainder.

 

If condition statement is used to check the modulus of the value of ‘num’ variable value by the value of ‘x’ variable is equal to 0. If the condition is true then execute the statement and print the factors of the given number.

Runtime Test Cases
 
Enter the Number : 27
The Factors are : 
1
3
9
27

 

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.81 seconds
10,853,191 unique visits