Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*4. 3. Dany jest ciąg liczb naturalnych wprowadzonych
- z klawiatury, zakończony zerem. Napisz program,
- który wypisze kolejne liczby ciągu w postaci iloczynu liczb pierwszych.
- Np. Dla ciągu liczb: 24, 100, 6, 1520, 0
- 2*2*2*3
- 2*2*5*5
- 2*3
- 2*2*2*2*5*19
- */
- #include <iostream>
- using namespace std;
- int main()
- {
- int n,k,licznik=0,silnia=1,i=0;
- cout<<"Podaj swoje liczby: "<<endl;
- int tab[1000];
- do
- {
- ++i;
- cout<<i<<". ";
- cin>>tab[i];
- }
- while (tab[i]!=0);
- //cout<<"I wartosc: "<<i<<endl;
- for (int a=1;a<=i;a++)
- {
- if (tab[a]!=0)
- {
- cout<<"Dla liczby "<<tab[a]<<endl;
- for (int y=2;y<=tab[a];y++)
- {
- if (tab[a]%y==0)
- {
- cout<<y<<"*";
- tab[a]=tab[a]/y;
- while (tab[a]%y==0)
- {
- tab[a]=tab[a]/y;
- cout<<y<<"*";
- }
- }
- }
- cout<<endl;
- }
- }
- }
Add Comment
Please, Sign In to add comment