Input a number and print its prime factors (Different method).
#include <stdio.h>
#include <conio.h>
int prime ( int );
void pfactor ( int );
void main ( )
{
int n;
clrscr ( );
printf("\n\n\n\t\t Enter a number..:"); scanf("%d",&n);
printf("\n\n\n\t\t PRIME FACTORS...:");
pfactor ( n );
getch ( );
}
void pfactor ( int n )
{
int d, i;
for ( i = 2; i <= n; i++ )
{
if ( prime ( i ) )
{
if ( n % i == 0 )
{
printf("%d, ",i);
n = n / i;
i--;
}
}
}
}
int prime ( int n )
{
int i;
for ( i = 2; i < n; i++ )
{
if ( n % i == 0 )
return 0;
}
return 1;
}
Click here to contact us
#include <stdio.h>
#include <conio.h>
int prime ( int );
void pfactor ( int );
void main ( )
{
int n;
clrscr ( );
printf("\n\n\n\t\t Enter a number..:"); scanf("%d",&n);
printf("\n\n\n\t\t PRIME FACTORS...:");
pfactor ( n );
getch ( );
}
void pfactor ( int n )
{
int d, i;
for ( i = 2; i <= n; i++ )
{
if ( prime ( i ) )
{
if ( n % i == 0 )
{
printf("%d, ",i);
n = n / i;
i--;
}
}
}
}
int prime ( int n )
{
int i;
for ( i = 2; i < n; i++ )
{
if ( n % i == 0 )
return 0;
}
return 1;
}
Click here to contact us
No comments:
Post a Comment