Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <ctime>
- using namespace std;
- int main()
- {
- int tab[10];
- int wynik=0;
- ofstream liczby;
- liczby.open("trzytys.txt");
- srand(time(NULL));
- for(int k=0; k<10; k++)
- {liczby<<rand()<<endl;}
- liczby.close();
- ifstream odczyt;
- odczyt.open("trzytys.txt");
- for(int k=0; k<10; k++)
- {odczyt>>tab[k];}
- odczyt.close();
- ofstream suma;
- suma.open("sumaliczb.txt");
- for(int k=0; k<10; k++)
- { while(tab[k]!=0)
- {
- wynik=wynik+tab[k]%10;
- tab[k]=tab[k]/10;
- }
- suma<<wynik<<endl;
- }
- suma.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement