Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <ctime>
- #include <cstdlib>
- #include <cstring>
- #include <string>
- #include <iostream>
- using namespace std;
- /* Описать функцию IsPowerN(K, N) логического типа, возвращающую True,
- если целый параметр K (> 0) является степенью числа N (> 1), и False
- в противном случае. Дано число N (> 1) и набор из 10 целых положительных чисел.
- С помощью функции IsPowerN найти количество степеней числа N в данном наборе*/
- bool IsPowerN(int K, int N){
- double k=K;
- if (k<N) k=-1;
- while (k>=N){
- k/=N;}
- if (k==1) return true;
- else return false;
- }
- int main(){
- srand(time(0));
- setlocale(0,"");
- x:
- int N;
- cout<<"Введите целое N>1:"<<endl;
- cin>>N;
- if (N<=1) {system("cls"); /*system("clean");*/ goto x;};
- cout<<endl;
- int b;
- int n=10;
- int ar[n];
- cout<<"Сейчас будут выбраны 10 случайных чисел от 0 до ..?"<<endl;
- cin>>b;
- cout<<endl;
- for (int i=0;i<n;i++){
- ar[i]=rand()%b;
- cout<<ar[i]<<' ';}
- cout<<endl;
- for (int i=0;i<n;i++){
- if (IsPowerN(ar[i], N)) cout<<endl<<ar[i]<<" является степенью "<<N;
- else cout<<endl<<ar[i]<<" не является степенью "<<N;}
- cout<<endl<<endl<<"Если хотите повторить - введите 1"<<endl;
- cin>>N;
- if (N==1) {system("cls"); /*system("clean");*/ goto x;}
- }
Advertisement
Add Comment
Please, Sign In to add comment