Arkanium77

Untitled

Apr 21st, 2016
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. #include <cmath>
  2. #include <ctime>
  3. #include <cstdlib>
  4. #include <cstring>
  5. #include <string>
  6. #include <iostream>
  7.  
  8. using namespace std;
  9. /*    Описать функцию IsPowerN(K, N) логического типа, возвращающую True,
  10.      если целый параметр K (> 0) является степенью числа N (> 1), и False
  11.      в противном случае. Дано число N (> 1) и набор из 10 целых положительных чисел.
  12.      С помощью функции IsPowerN найти количество степеней числа N в данном наборе*/
  13.  
  14. bool IsPowerN(int K, int N){
  15.     double k=K;
  16.     if (k<N) k=-1;
  17.     while (k>=N){
  18.         k/=N;}
  19.     if (k==1) return true;
  20.     else return false;
  21.    
  22. }
  23.  
  24. int main(){
  25.     srand(time(0));
  26.     setlocale(0,"");
  27.     x:
  28.     int N;
  29.     cout<<"Введите целое N>1:"<<endl;
  30.     cin>>N;
  31.     if (N<=1) {system("cls"); /*system("clean");*/ goto x;};
  32.     cout<<endl;
  33.     int b;
  34.     int n=10;
  35.     int ar[n];
  36.     cout<<"Сейчас будут выбраны 10 случайных чисел от 0 до ..?"<<endl;
  37.     cin>>b;
  38.     cout<<endl;
  39.    
  40.     for (int i=0;i<n;i++){
  41.         ar[i]=rand()%b;
  42.         cout<<ar[i]<<' ';}
  43.         cout<<endl;
  44.     for (int i=0;i<n;i++){
  45.         if (IsPowerN(ar[i], N)) cout<<endl<<ar[i]<<" является степенью "<<N;
  46.         else cout<<endl<<ar[i]<<" не является степенью "<<N;}
  47.    
  48.     cout<<endl<<endl<<"Если хотите повторить - введите 1"<<endl;
  49.      cin>>N;
  50.     if (N==1) {system("cls"); /*system("clean");*/ goto x;}
  51. }
Advertisement
Add Comment
Please, Sign In to add comment