Witam niedawno zacząłem zabawę z C++ i napisałem program w Pascalu który rozkłada liczbę na czynniki pierwsze program czynniki_pierwsze;
//uses crt;
var
tab: array [1..20] of integer;
tab1:array [1..20] of integer;
a,b,c,x,y: integer;
begin
clrscr;
writeln ('Podaj liczb©');
readln (a);
b:=2;
x:=1;
repeat
if a mod b=0 then
begin
tab1[x]:=b;
tab[x]:=a;
a:=a div b ;
x:=x+1;
tab1[x]:=b;
tab[x]:=a;
end
else
b:=b+1;
until a=1;
for y:=2 to x do
begin
if tab[y+1]=0 then
write(tab1[y])
else
write(tab1[y],' * ');
end;
writeln(' = ', tab[1]);
readln;
end.//
chciałbym go teraz prze konwertować na c++ ale mi to troszkę nie wyszło
//#include <iostream>
using namespace std;
int main()
{
int tab[20];
int tab1[20];
int d,a,b=2,c,x=1,y;
cout<<"Podaj liczbe";
cin>>a;
do
{
if (a%b==0)
{
tab1[x]=b;
tab[x]=d;
d=a/b;
x++;
tab1[x]=b;
tab[x]=d;
}
else
b++;
}
while (a==1);
for (y=2;y<=x;y++)
{
if (tab[y+1]==0)
{
cout<<tab[1];
}
else
cout<< tab1[y]<<" * ";
}
cout<<"="<<tab[1];
//cout << "Hello world!" << endl;
return 0;
}//
co zrobiłem źle bardzo prosze o pomoc program oczywiście w c++ nie działa