Write a program to generate prime factors of a given integer?

Answer Posted / shruthi chandran

voiid primeFactors(int n)
{
while (n%2 == 0)
{
printf("%d ", 2);
n = n/2;
}
for (int i = 3; i <= sqrt(n); i = i+2)
{

while (n%i == 0)
{
printf("%d ", i);
n = n/i;
}
}

if (n > 2)
printf ("%d ", n);
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can a program be made to print the name of a source file where an error occurs?

731


How can you be sure that a program follows the ANSI C standard?

1131


What is a file descriptor in c?

562


1) There is a singing competition for children going to be conducted at a local club. Parents have been asked to arrive at least an hour before and register their children’s names with the Program Manager. Whenever a participant registers, the Program Manager has to position the name of the person in a list in alphabet order. Write a program to help the Program Manager do this by placing the name in the right place each time the Program Manger enters a name. The Logic should be written in Data Structures?

1918


What is array in C

710






What is nested structure?

575


What is header file in c?

604


Which is the best website to learn c programming?

584


What is a const pointer in c?

670


What is NULL pointer?

677


What is LINKED LIST? How can you access the last element in a linked list?

633


What is the Purpose of 'extern' keyword in a function declaration?

654


What does double pointer mean in c?

584


What is p in text message?

540


Tell me is null always defined as 0(zero)?

674