Кто может помочь? Объяснить этот код с помощью комментариев! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Кто может помочь? Объяснить этот код с помощью комментариев!

#include <iostream> #include <math.h> #include <cstdlib> #include <ctime> using namespace std; bool IsPower5(int K) { while (!(K % 5)) K /=5; return (K == 1); } int main(void) { srand(time(0)); int i,K,p; for (i=1;i<=10;i++) { K=rand()%100; cout<<"K="<<K<<" "; p+=IsPower5(K); } cout<<endl<<"количество степеней числа 5:"<<p<<endl; return 0; }

2nd Dec 2020, 6:22 PM
Vrueci
Vrueci - avatar
1 Answer
0
#include <iostream> #include <cmath> #include <cstdlib> #include <ctime> int IsPower5(int K) { if(K == 1) return K; while (!(K % 5)) K /= 5; return (K == 1); } int main() { int K, p {0}; srand(time(nullptr)); for (int i {0}; i < 10; i++) { K = rand() % 100 + 1; std::cout << "K = " << K << "\n"; p += IsPower5(K); } std::cout << "количество степеней числа 5: " << p << std::endl; return 0; }
3rd Dec 2020, 1:59 PM
Ipang