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

What is %lu in c?

693


What is a pointer value and address in c?

638


what value is returned to operating system after program execution?

1609


A SIMPLE PROGRAM OF GRAPHICS AND THEIR OUTPUT I WANT SEE WAHAT OUTOUT OF GRAPHICS PROGRAM

1707


What is function and its example?

635






What are the c keywords?

757


What is uint8 in c?

651


What is infinite loop?

633


The program will first compute the tax you owe based on your income. User is prompted to enter income. Program will compute the total amount of tax owed based on the following: Income Tax 0 - $45,000 = 0.15 x income $45,001 - $90,000 = 6750 + 0.20 x (income – 45000) $90,001 - $140,000 = 15750 + 0.26 x (income – 90000) $140,001 - $200,000 = 28750 + 0.29 x (income – 140000) Greater than $200,000 = 46150 + 0.33 x (income – 200000) Dollar amounts should be in dollars and cents (float point numbers with two decimals shown). Tax is displayed on the screen.

1075


how can I convert a string to a number?

605


hi friends how r u as soon in satyam my interview is start but i m very confusued ta wat i do plz help me frndz wat can i do plz tell me some question and answers related with "C" which r asked in the interview .

1910


Hi can anyone tell what is a start up code?

1627


What is pointer to pointer in c with example?

557


Is this program statement valid? INT = 10.50;

695


Program will then find the largest of three numbers using nested if-else statements. User is prompted to enter three numbers. Program will find the largest number and display it on the screen. All three numbers entered by the user are also displayed. If user enters 21, 33, and 5, the output should be as follows: You entered: 21, 33 and 5. The largest number is 33.

1021