answersLogoWhite

0


Best Answer

The following program prints all the prime factors of a given number 'n':# include # include // A function to print all prime factors of a given number nvoid primeFactors(int n){ // Print the number of 2s that divide n while (n%2 == 0) { printf("%d ", 2); n = n/2; } // n must be odd at this point. So we can skip one element (Note i = i +2) for (int i = 3; i <= sqrt(n); i = i+2) { // While i divides n, print i and divide n while (n%i == 0) { printf("%d ", i); n = n/i; } } // This condition is to handle the case whien n is a Prime number // greater than 2 if (n > 2) printf ("%d ", n);} /* Driver program to test above function */int main(){ int n = 315; primeFactors(n); return 0;}

User Avatar

Wiki User

10y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

#include<stdio.h>

#include<conio.h>

int prime(int);

int main()

{

int x;

printf("\nInput an integer\n");

scanf("%d",&x);

prime(x);

getche();

}

prime(int x)

{

int a;

for(a=2;a<=x;a++)

{

if(x%a==0)

{

printf("%d ",a);

prime(x/a);

break;

}

}

}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

The program is as follows:

#include <stdio.h>

void main()

{

int number = 0;

int count = 1;

int i = 0;

printf("Enter the number whose prime factor is to be determined: \t"\n);

scanf("%d", &number);

while((number /2) > ++count)

{

if(number % count == 0)

{

printf("factor = [%d]\n", count);

}

}

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a c program to find prime factor using recursion?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Movies & Television

How do you Write 7 in prime factorization?

What is the greatest common factor of 525 and 735


How do you write 270 as a product of it prime factor?

As a product of its prime factors: 2*3*3*3*5 = 270


How do you write 30 as a product of its prime factor?

29 is already prime. Prime numbers can't be products of primes.


What is the only way to create a factor tree?

Write the composite number you want to factor on a piece of paper. Write one of its factor pairs underneath it. If possible, keep breaking each factor down until all the factors are prime. All composite numbers can be expressed as unique products of prime numbers. This is accomplished by dividing the original number and its factors by prime numbers until all the factors are prime. A factor tree can help you visualize this. Example: 210 210 Divide by two. 105,2 Divide by three. 35,3,2 Divide by five. 7,5,3,2 Stop. All the factors are prime.


Is 35 a prime or a factor?

35 can be a factor, but it is not prime.