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

What's the right way to use errno?

624


Explain about block scope in c?

661


Lists the benefits of c programming language?

598


hi any body pls give me company name interview conduct "c" language only

1667


What is data types?

641






what do the 'c' and 'v' in argc and argv stand for?

646


main(){char *str;scanf("%s",str);printf("%s",str); }The error in the above program is: a) Variable 'str' is not initialised b) Format control for a string is not %s c) Parameter to scanf is passed by value. It should be an address d) none

726


What is sizeof int?

637


What are the different categories of functions in c?

645


FILE PROGRAMMING

1779


Explain what is gets() function?

633


What is pointer & why it is used?

604


What is mean by Data Driven framework in QTP? Can any one answer me in details on this regard.

1783


List out few of the applications that make use of Multilinked Structures?

1303


What is pointer and structure in c?

574