Anonymous user
Factors of an integer: Difference between revisions
→{{header|C}}
Line 272:
=={{header|C}}==
<lang c>#include <
#include <
typedef struct
{
} Factors;
void xferFactors(
{
fctrs->list = (newSize > flix) ?
for (ij = 0, ix
}▼
▲ fctrs->list = malloc( newSize * sizeof(int));
▲ fctrs->list[ix] = flist[ij];
▲ fctrs->count = newSize;
}
Factors *factor(
{
fctrs->list = NULL;
for (dvsr = 1; dvsr * dvsr <
{
if ( flix == 300) {▼
xferFactors( fctrs, flist, flix );▼
continue;
if (flix ==
{
flist[flix++] = dvsr;▼
flix
▲ if (dvsr*dvsr == num)
}
xferFactors( fctrs, flist, flix );▼
if (dvsr*dvsr == num)
return fctrs;▼
}
int main(int argc, char *argv[])
{
{
(void) printf("\nfactors of %d are:\n ", nums2factor[i]);
for (j = 0; j
{
(void) printf("%c %d", sep, ftors.list[j]);
sep =
(void) printf("\n");
}
return EXIT_SUCCESS;
}</lang>
|