Descompose in prime numbers

I have to make an algorithm that descompose the number in prime factors.
I did it but it`s not good because it shows "*" at the end and that`s the problem. My idea was to make a verification so if it is the last number it doesn`t show "*" at the end or to make a new viriable " which can help in verification.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  #include<iostream>
using namespace std;
int main()
{
int n,d=2,p,s;
cout<<"n=";cin>>n;
while(n>1)
{
p=0;
while(n%d==0)
{
p=p+1;
n=n/d;
}
if(p) {cout<<d<<"^"<<p<<"*";}
d=d+1;
}
return 0;}
Topic archived. No new replies allowed.