Not Yet Answered # Finding prime factors and distinct prime factors

WaltP 2,905 dkalita 110 c coder -3 c coder -3 rajanpathak -3 Hi I'm having a problem implementing a mini shopping cart drop down in the header to show the user all the products they have in their shopping cart. It seems the only solution for this is Ajax, and I've looked all over and can't find anything that I could possibly ...

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();
}
```

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

1

You need to format your code before posting...

No idea what you are asking. Distinct prime factors? Of what? Show us an example...

0

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

Explain your query in a little more detail.

-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)

}

}

}

0

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;

}

}

}

-2

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

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

Hello All ...

Iam Getting An Error With try to excecute the stored procedure .

I have Have Sql database , the stored procedure like so :

```
USE [MPRS]
GO
/****** Object: StoredProcedure [dbo].[Search_Licenses_By_Number] Script Date: 26-Nov-16 8:06:52 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE ...
```

Help! I want to create a java program that finds the highest even integer among the values entered by the user. Stop asking values when a value less than 1 have been entered. If no even integer is entered, display "No Even Integer"

Here is the sample output that I ...