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 / bibek

/*Program To Generate The Prime Factors Of An Entered
Numbers*/

/*Header Files*/
#include<stdio.h>


/*Function Prototypes*/
void factorcheck(long unsigned int prime,long unsigned int
num );
void primefind(long unsigned int num, long unsigned int
startnum);

void main()
{

long unsigned int num;

printf("\n Enter A Positive Number:");
scanf("%d", &num);
printf("\n ");

/*Call To the primefind() function*/
primefind(num,
1); /*Find
a prime less than the given number*/

if (num==0)
{
printf(" 0 \n \n");
}
else if (num==1)
{
printf(" 1 \n \n");
}
else
{
printf("\b \n
\n "); /*Delete the
extra 'x' left in the end*/
}

}

void primefind(long unsigned int num, long unsigned int
startnum)
{

long unsigned int counter1, counter2, primecheck;
char primestat;

for(counter1 = startnum; counter1<=num; counter1++)
{

for (counter2 = 2; counter2< counter1; counter2++)
{


primecheck = counter1 %
counter2; /* Check If The Chosen Number
(counter1) is divisible

by numbers less than it excluding 1*/
if (primecheck != 0 )
primestat
= 't'; /*The Number Is
Prime*/

else /*(So
Far)*/
{
primestat
= 'f'; /*The Number Is
Not Prime*/
break;
}

}

if (primestat =='t' || counter1 ==2)
{
factorcheck
(counter1,num); /*This Calls
The Function factorcheck()*/

break;
/* which checks if the prime number */
}
/*generated is a factor of the given
number*/


}

}

void factorcheck(long unsigned int prime, long unsigned int
num)
{
long unsigned int remainder;

remainder = num%prime;

if (remainder ==
0) /*since the remainder is 0,
the prime number is a factor*/
{
printf("%dx", prime);
primefind((num/prime), 1); /*Find
Another prime number*/
return;
}
else
primefind(num, prime+1); /*Since
The Generated Prime is not a factor,*/
/*the function
checks for the next prime number available*/
}

Is This Answer Correct ?    9 Yes 14 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Hai what is the different types of versions and their differences

1935


What is c definition?

1265


Can the sizeof operator be used to tell the size of an array passed to a function?

1109


What is self-referential structure in c programming?

1204


regarding pointers concept

2033


How can you access memory located at a certain address?

1112


A float occupies 4 bytes in memory. How many bits are used to store exponent part? since we can have up to 38 number for exponent so 2 ki power 6 6, 6 bits will be used. If 6 bits are used why do not we have up to 64 numbers in exponent?

2311


What is new line escape sequence?

1331


What is the 'named constructor idiom'?

1083


What is the purpose of sprintf?

1128


Is fortran faster than c?

1033


What is a stream water?

1207


Using which language Test cases are added in .ptu file of RTRT unit testing???

4269


Is it acceptable to declare/define a variable in a c header?

1111


what are # pragma staments?

2040