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 is the meaning of 2d in c?
What are multibyte characters?
What is logical error?
how to print electricity bill according to following charges first 100 units -1rs per unit for next 200 units-1.50 rs per unit without using conditions
Explain how do you sort filenames in a directory?
Can we change the value of #define in c?
Explain can you assign a different address to an array tag?
how to construct a simulator keeping the logical boolean gates in c
Write a code to generate divisors of an integer?
What is the most efficient way to count the number of bits which are set in an integer?
write a program fibonacci series and palindrome program in c
write a program to convert a expression in polish notation(postfix) to inline(normal) something like make 723+* (2+3) x 7 (not sure) just check out its mainly printing expression in postfix form to infix.
What is the code for 3 questions and answer check in VisualBasic.Net?
what will be the output for the following main() { printf("hi" "hello"); }
What are the advantages and disadvantages of a heap?