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
Why is extern used in c?
What is a macro in c preprocessor?
What is a 'null pointer assignment' error?
why to assign a pointer to null sometimes??how can a pointer we declare get assigned with a garbage value by default???
write a program to print data of 5 five students with structures?
Explain what is the general form of a c program?
Explain how can you be sure that a program follows the ansi c standard?
What is a stream water?
Why c is called procedure oriented language?
What is the difference between typedef and #define?
how to write a c program to print list of fruits in alpabetical order?
Implement bit Array in C.
What are the advantages of c language?
Difference between strcpy() and memcpy() function?
What kind of structure is a house?