factors using recursion
/* C Program to print prime factors*/
#include<stdio.h>
void PFactors( int num);
void IPFactors( int n);
int main( )
{
int num;
printf("Enter a number : ");
scanf("%d", &num);
printf("\nUsing Recursion :: \n");
PFactors(num);
printf("\n");
printf("\nUsing Iteration :: \n");
IPFactors(num);
printf("\n");
return 0;
}/*End of main()*/
/*Recursive*/
void PFactors( int num)
{
int i = 2;
if( num == 1 )
return;
while( num%i != 0 )
i++;
printf("%d ", i);
PFactors(num/i);
}/*End of PFactors()*/
/*Iterative*/
void IPFactors( int num)
{
int i;
for( i = 2; num!=1; i++)
while( num%i == 0 )
{
printf("%d ", i);
num = num/i;
}
}/*End of IPFactors()*/
Also in C:
- struct main function c in unix
- BlockChain in c
- ternary operator in c
- how to mutex lock in c
- boolean function c
- How to pull images from Docker Registry
- double return type in c
- how to find the nth row of pascal's triangle in c
- sdl out of memery
- Access denied creating xampp-control.ini
- atoi c
- how to use malloc in c
- main function in c
- is it possible to access argv in function
- how to open a website in c
- sleep in c programming
- logarithmus c math.h
- how to check where the last char is in a string c
- what is strikethrough in markdown
- how to use ? in c
- es fibo
- how do pointers work in c programmwiz
- select all file from date powershell
- c check if null