Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Why is extern used in c?

1093


What is a macro in c preprocessor?

1103


What is a 'null pointer assignment' error?

1220


why to assign a pointer to null sometimes??how can a pointer we declare get assigned with a garbage value by default???

1973


write a program to print data of 5 five students with structures?

2048


Explain what is the general form of a c program?

1099


Explain how can you be sure that a program follows the ansi c standard?

1481


What is a stream water?

1225


Why c is called procedure oriented language?

1054


What is the difference between typedef and #define?

1065


how to write a c program to print list of fruits in alpabetical order?

2306


Implement bit Array in C.

1153


What are the advantages of c language?

1099


Difference between strcpy() and memcpy() function?

1155


What kind of structure is a house?

1048