Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     fstream dane;
  10.     dane.open("dane1.txt");
  11.     fstream wynik;
  12.     wynik.open("wynik1.txt", ios::out);
  13.  
  14.  
  15.  
  16.     while(!dane.eof())
  17.     {
  18.         int tab[10]={0};
  19.         int k=2;
  20.         int i=0;
  21.         int x=0;
  22.         dane >> x;
  23.         while(x>1)
  24.         {
  25.             while(x%k==0)
  26.             {
  27.                 i++;
  28.                 tab[k]=i;
  29.                 x/=k;
  30.             }
  31.             k++;
  32.             i=0;
  33.  
  34.         }
  35.         for(int y=1;y<10;y++)
  36.         {
  37.             if(tab[y]!=0)
  38.             {
  39.                 if(tab[y]==1) wynik<<y;
  40.                 if(tab[y]>1)
  41.                 {
  42.                     wynik << y << "^" << tab[y] << " ";
  43.                 }
  44.  
  45.             }
  46.         }
  47.  
  48.  
  49.  
  50.  
  51.     }
  52.             wynik.close();
  53.             dane.close();
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement