<< Thread split from here >>

hello..
i did not get it the programs that u wrote it..
for my own..
im looking for the factorial of the number that we entered..
for example..
12 the factor of this is 2 2 3..that wat i want to mean..
in wat would be the real program to be used using this Recursion in factorization..even i will ask the user t enter to numbers to input..
in factorizatin we should used the N%K==0;,..right?for our formula..

im keneth from philippines a collage student at this time...
thank u..

Edited by Nick Evan: Split

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by bun

check this code

``````#include<stdio.h>
# include <stdlib.h>
int main()
{
int x = 0;
printf("plz enter a number : ");
scanf("%d",&x);

int y = 2 , z = 0;
int * factors = (int*)malloc(100 * sizeof(int));
while (x != 1)
{
if (x % y == 0)
{
x = x /y;
factors[z] = y;
z++;
}
else y++;
}
z--;
int a = 0;
while (a <= z)
{
printf("%d ",factors[a]);
a++;
}

return 0;
}``````
Please don't just give away code to students. It's counterproductive.

check this code

OK...

``````#include<stdio.h>
# include <stdlib.h>
int main()
{
int x = 0;
printf("plz enter a number : ");``````

``````scanf("%d",&x);

int y = 2 , z = 0;
int * factors = (int*)malloc(100 * sizeof(int));``````

Declaring variables after executable statements is illegal in Standard C -- at least with most C compilers in use.

``````while (x != 1)
{
if (x % y == 0)
{
x = x /y;
factors[z] = y;
z++;
}
else y++;
}
z--;
int a = 0;
while (a <= z)
{
printf("%d ",factors[a]);
a++;
}

return 0;
}``````

Finally, what does finding the factors of a number have to do with the factorial of a number?

Other than that, it is nicely formatted. Unfortunately, you attempted to do his homework for him. We don't do that here. We help them write their own code.