Ziomnexpl

dzielniki liczb z pliku

Oct 21st, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  5. using namespace std;
  6.  
  7. ofstream zapis("zapis.txt");
  8. ifstream odczyt("dane.txt");
  9.  
  10. void rozklad(int a)
  11. {
  12.     int d=2;
  13.     while(a!=1)
  14.     {  
  15.         if(a%d==0)
  16.         {
  17.             cout<<d<<" ";
  18.             zapis<<d<<" ";
  19.             a=a/d;
  20.         }
  21.         else
  22.         d++;
  23.     }
  24. }
  25.  
  26. int main(int argc, char** argv) {
  27.     int a,i;
  28.     for(i=1;i<=7;i++)
  29.     {
  30.     do
  31.     {
  32.     odczyt>>a;
  33.     cout<<"dzielniki "<<a<<"->";
  34.     }
  35.     while(a<=1);
  36.     zapis<<a<<"-";
  37.     rozklad(a);
  38.     zapis<<endl;
  39.     cout<<endl;
  40.     }
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment