For Programmers: Free Programming Magazines  


Home > Archive > Prolog > December 2005 > Finding A divisors of Number









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Finding A divisors of Number
isaihat

2005-12-11, 10:24 am

Hye programmers,
I have this problem:-
I want to create a program, the input is a Number and the output is list of its divisors.

and thank u for help
Ra3a

2005-12-20, 5:58 pm

quote:
Originally posted by isaihat
Hye programmers,
I have this problem:-
I want to create a program, the input is a Number and the output is list of its divisors.

and thank u for help




Try this:

private void prmNo_Click(object sender, System.EventArgs e)
{
long lPrimeNo =long.Parse(this.txtEnterPrimeNumber.Text);

//Clear Listbox values
this.lstPno.Items.Clear();

for(double lidx = 1;lidx < lPrimeNo; lidx++)

{
double dblPrime_Number = lPrimeNo / lidx;
string sDivisor = dblPrime_Number.ToString();
//extract whole numbers only
if(sDivisor.IndexOf(".",1) <=0)
{
this.lstPno.Items.Add(dblPrime_Number.ToString());
}


}

}
Ra3a

2005-12-20, 7:41 pm

sorry correction

private ArrayList GetDivisors(long lngNumber)
{

long lPrimeNo =long.Parse(this.txtEnterPrimeNumber.Text);
//long lValue;

//Arraylist to hold divisors
ArrayList sAryLst = new ArrayList();

//Clear preceeding values
this.lstPno.Items.Clear();
//lValue = 0;

for(double lidx = 1;lidx < lPrimeNo; lidx++)

{
double dblPrime_Number = lPrimeNo / lidx;
string sDivisor = dblPrime_Number.ToString();
//extract whole numbers only any number that is not a whole number is not a divisor
if(sDivisor.IndexOf(".",1) <=0)
{
sAryLst.Add(lPrimeNo/dblPrime_Number);
this.lstPno.Items.Add(lPrimeNo/dblPrime_Number);

}

}

//Return divisible numbers
return sAryLst;


}
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com