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
differentiate built-in functions and user – defined functions.
Why c is called a middle level language?
hai iam working in sap sd module for one year and working in lumax ind ltd in desp department but my problem is i have done m.b.a in hr/marketing and working sap sd there is any combination it. can you give right solution of my problem. and what can i do?
What is the difference between typedef struct and struct?
Can static variables be declared in a header file?
Write a program in c to replace any vowel in a string with z?
What are pragmas and what are they good for?
What is c programming structure?
Is javascript based on c?
What is an example of structure?
What are run-time errors?
Difference between macros and inline functions? Can a function be forced as inline?
What is realloc in c?
What is ## preprocessor operator in c?
What is action and transformation in spark?