Hi guys I have some problem regarding getting prime factors and distinct prime factors.
I manged to get the prime factors but I got stuck on how to get the distinct prime factors.........I don't know how to select unique prime factors and print them....Help me out guys........

Thank you in advance....

My code to get just the prime numbers is............

#include<stdio.h> 
#include<conio.h> 

int main() 
{ 
int n,i; 
printf("Enter a Number:"); 
scanf("%d",&n); 
printf("\n\nPrime Factors of %d is: ",n); 
for(i=2;i<=n;i++) 
{ 
if(n%i==0) 
{ 
printf("%d,",i); 
n=n/i; 
i--; 
if(n==1) 
break; 
} 
} 
getche(); 
}

Edited 7 Years Ago by WaltP: Added CODE tags -- with all the help about them, how could you miss using them????

I dont know what u r asking but a liked your algo for finding prime factors.

Explain your query in a little more detail.

Hi guys I have some problem regarding getting prime factors and distinct prime factors.
I manged to get the prime factors but I got stuck on how to get the distinct prime factors.........I don't know how to select unique prime factors and print them....Help me out guys........

Thank you in advance....

My code to get just the prime numbers is............

#include<stdio.h> 
#include<conio.h> 

int main() 
{ 
int n,i; 
printf("Enter a Number:"); 
scanf("%d",&n); 
printf("\n\nPrime Factors of %d is: ",n); 
for(i=2;i<=n;i++) 
{ 
if(n%i==0) 
{ 
printf("%d,",i); 
n=n/i; 
i--; 
if(n==1) 
break; 
} 
} 
getche(); 
}

unique prime factor
#include<stdio.h>
void main()
{

int n,i,q,u;
printf("enter no to find factor");
scanf("%d",&n);
for(i=2;i<n;i++)
{

if(n%i==0)
{
if(u!=i){
printf("\t%d",i);
u=i;
}

n=n/i;
i--;
if(n==1)

}
}

}

Hi guys I have some problem regarding getting prime factors and distinct prime factors.
I manged to get the prime factors but I got stuck on how to get the distinct prime factors.........I don't know how to select unique prime factors and print them....Help me out guys........

Thank you in advance....

My code to get just the prime numbers is............

#include<stdio.h> 
#include<conio.h> 

int main() 
{ 
int n,i; 
printf("Enter a Number:"); 
scanf("%d",&n); 
printf("\n\nPrime Factors of %d is: ",n); 
for(i=2;i<=n;i++) 
{ 
if(n%i==0) 
{ 
printf("%d,",i); 
n=n/i; 
i--; 
if(n==1) 
break; 
} 
} 
getche(); 
}

unique prime factor
#include<stdio.h>
void main()
{

int n,i,q,u;
printf("enter no to find factor");
scanf("%d",&n);
for(i=2;i<n;i++)
{

if(n%i==0)
{
if(u!=i){
printf("\t%d",i);
u=i;
}

n=n/i;
i--;
if(n==1)
break;
}
}

}

//Compiler Turbo C++ IDE
//If you give Prime No as an ip it will show the result like "No is Prime"
//With Non Prime Number It will Show Desired Result

//For further Doubt mail me @ [removed]

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
void primefactors(int);
int pf=0;
void main()
{
int number;
int i,j,ct=0;
clrscr();
printf("Enter the Number:");
scanf("%d", &number);

if(number==2){
printf("Number is Prime and Prime Factor is %d",number);
exit(0);
}

for(i=2;i<=number;i++)
{
if(number%i==0 && i<number)
{
ct++;
printf("Number is not prime\n");
primefactors(number);
break;
}

if(number%i==0 && ct==0){
printf("No is Prime");
break;
}




}
//return 0;
getch();

}

void primefactors(int number)
{
int i,k=0;
int ct;
static int j;
int p[1000][2];

j=number;


printf("Prime factors are\n");
for(i=2;i<=number;i++)
{  ct=1;
   while(j%i==0)
   {
  // ct=ct+1;
   printf("%d ",i);
    // printf("*");
  // j=j/i;

   p[k][0]=i;
   p[k][1]=ct;
   ct=ct+1;
   j=j/i;
// printf("%d\n",p[k][0]);
// printf("%d\n",p[k][1]);


}
 if(ct!=1 && j%i!=0)
 {
 k++;
 }


}
printf("\n\n");

for(i=0;i<k;i++)
{
printf("%d %d ",p[i][0],p[i][1]);
printf("\n");
pf=pf+p[i][1];
}

printf("Total No of prime Factors are:%d\n",pf);
printf("Distinct No. prime factors are:%d",k);

}

Edited 5 Years Ago by Ezzaral: Added code tags and removed email. Read the rules. Keep it on site.

Comments
Do NOT give solutions to problems. Students don't learn if you do their homework for them.
This article has been dead for over six months. Start a new discussion instead.