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
Explain what does the format %10.2 mean when included in a printf statement?
Are the outer parentheses in return statements really optional?
Is int a keyword in c?
How many parameters should a function have?
What is the function of volatile in c language?
How is a structure member accessed?
How can I read data from data files with particular formats?
Explain how can I prevent another program from modifying part of a file that I am modifying?
How can you find out how much memory is available?
Can a pointer be volatile in c?
Can a variable be both constant and volatile?
How does struct work in c?
Is it possible to pass an entire structure to functions?
Is flag a keyword in c?
How can I avoid the abort, retry, fail messages?