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

Answer Posted / varshil shah

#include<stdio.h>
#include<conio.h>
void factors(int);
void main()
{
int num,fact,i;
clrscr();
printf("\n Enter a number :::");
scanf("%d",&num);
if(num==2)
{
factors(num);
}
else
{
for(i=2;i<=num;i++)
{
if(num%i==0)
{
factors(i);
}
}
}
getch();
}
void factors(int n)
{
int i,notprime=0;
if(n==2)
{
printf("\n Prime factor is 2");
}
else
{
for(i=2;i<n;i++)
{
if(n%i==0)
{
notprime++;
}
}
if(notprime==0)
{
printf("\n Prime factor is %d",i);
}
}
}

Is This Answer Correct ?    5 Yes 8 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what does the format %10.2 mean when included in a printf statement?

784


Are the outer parentheses in return statements really optional?

581


Is int a keyword in c?

559


How many parameters should a function have?

670


What is the function of volatile in c language?

670






How is a structure member accessed?

592


How can I read data from data files with particular formats?

607


Explain how can I prevent another program from modifying part of a file that I am modifying?

644


How can you find out how much memory is available?

620


Can a pointer be volatile in c?

539


Can a variable be both constant and volatile?

564


How does struct work in c?

611


Is it possible to pass an entire structure to functions?

563


Is flag a keyword in c?

682


How can I avoid the abort, retry, fail messages?

665