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's the right way to use errno?
Explain about block scope in c?
Lists the benefits of c programming language?
hi any body pls give me company name interview conduct "c" language only
What is data types?
what do the 'c' and 'v' in argc and argv stand for?
main(){char *str;scanf("%s",str);printf("%s",str); }The error in the above program is: a) Variable 'str' is not initialised b) Format control for a string is not %s c) Parameter to scanf is passed by value. It should be an address d) none
What is sizeof int?
What are the different categories of functions in c?
FILE PROGRAMMING
Explain what is gets() function?
What is pointer & why it is used?
What is mean by Data Driven framework in QTP? Can any one answer me in details on this regard.
List out few of the applications that make use of Multilinked Structures?
What is pointer and structure in c?