-1

<< 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..
can u help me about this problem program..??

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

Edited by Nick Evan: Split

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

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;
}
Votes + Comments
Please don't just give away code to students. It's counterproductive.
1

check this code

OK...

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

Improper English. It's spelled "Please"

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.

Votes + Comments
Nice one :)
-1

thank u for this program..
and i hope i can ask u more programs that wat i want to run..
thank u for this..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.