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
What are the uses of a pointer?
What are the types of type specifiers?
C program to find all possible outcomes of a dice?
How can I swap two values without using a temporary?
What is the significance of scope resolution operator?
How can I change their mode to binary?
What does calloc stand for?
Explain what is the concatenation operator?
Why c is known as a mother language?
What do you mean by c what are the main characteristics of c language?
What is sizeof int?
What is size of union in c?
write a program to rearrange the array such way that all even elements should come first and next come odd
What are the Advantages of using macro
Explain modulus operator. What are the restrictions of a modulus operator?