<< 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..

Recommended Answers

All 3 Replies

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;
}
commented: Please don't just give away code to students. It's counterproductive. -4

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.

commented: Nice one :) +12

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.