-
passing values in array
trying to take values at i, if x is moded by i and equals 0 then scan factor into array, then print value of factored array,,, problem is it loops permanently or gives me a whole bunch of garbage, if anyone can point me in the right direction it would be appreciated,,,,
thnx
Code:
int Factor ()
{
int i=0, x=0, num1 , j=0;
int n[50];
x=GetNum(num1);
printf("The Factors are:\n");
for ( i = x; i > 0; i--)
{
if (x % i == 0)
for(j=i; j > 0; j++)
{
scanf(" %d",&n[j]);
for(j=0; j>=50; j++)
{
printf("%d ",&n[j]);
}
}
}
printf("\n\n");
}
-
OK. I've just thrown this together, it may just compile without the use of duct-tape.
Code:
#include <stdio.h>
int main(int argc, char* argv[])
{
int i=0, j=0;
int x=54;
int n[50];
printf("The Factors are:\n");
for (i=1;i < (x/2);i++)
{
if (x % i == 0)
{
n[j]=i;
j++;
}
}
for(i=0; i<j; i++)
printf("%d ",n[i]);
printf("%d ",x);
printf(" are all factors of %d\n",x);
return 0;
}
I hope that's along the lines of what you're trying to accomplish.
-
your code compiles execpt there is no printed output, i guess there is an error in logic somewhere thnx for the help
-
this worx thnx man
Code:
int Factor ()
{
int i=0, x=0, num1 , j=0;
int n[50];
x=GetNum(num1);
printf("The Factors are:\n");
for ( i=x; i > 0; i--)
{
if (x % i == 0)
{
n[j]=i;
j++;
}
}
for(i=0; i<j; i++)
{
printf("%d ",n[i]);
}
printf(" are all factors of %d\n",x);
printf("\n\n");
}