По разделам

 

Решение задачи Proc 26


Описать функцию IsPower5(K) логического типа, возвращающую
TRUE, если целый параметр K (> 0) является степенью числа 5, и FALSE в
противном случае. С ее помощью найти количество степеней числа 5 в
наборе из 10 целых положительных чисел.

Код (C/C++)

# include <iostream>
# include <windows.h>
# include <cmath>
# include <iomanip>
# include <fstream>
 
using namespace std;
 
bool IsPower5(int K);
 
int main()
{
   SetConsoleCP(1251);
   SetConsoleOutputCP(1251);
   
   int answer = 0;
   int K;
   ifstream in ("Proc26.txt");
   
   cout << "Набор чисел: ";    while (in >> K) {
      cout << K << " ";       if (K>0) {
        if (IsPower5(K)) ++answer;
      }
   }
   cout << endl;
   cout << "Количество степеней числа 5 в наборе = " << answer << endl;
   in.close();
   system ("pause");
   return 0;
}
 
bool IsPower5 (int K)
{
   int i = 1;
   while (i<K) {
     i*=5;
   }
   return i == K;     
}

Код (Python)

import random
import math

def IsPower5(K):
    x = int(math.log(K,5))
    if K == 5**x:
        return True
    return False

s = 0
L = [5**random.randrange(1,10)+random.randrange(0,2) for i in range(0,10)]
for i in range(0,len(L)):
    x = L[i]
    print(x,end="; ")
    s += int(IsPower5(x))

print("\nAmount of IsPower5:",s)
									

Код (Pascal)

program Proc26;
 
Function IsPower5(K:Integer):Boolean;
begin
 While (K>=5) do
  begin
   if ((k mod 5)<>0) and (k<>1) then
    begin
     K:=0;
     IsPower5:=False;
    end;
   K:=k div 5;
  end;
 if K=1 then IsPower5:=True
 else IsPower5:=False;
end;
 
var
 i,N,Res:Integer;
 
begin
 for i:=1 to 10 do
  begin
   Write('N :');
   Readln(N);
   if IsPower5(N) then Inc(Res);
  end;
 Writeln(Res);
end.
									




Proc. Абрамян
Proc 1 Просмотров: 6575
Proc 2 Просмотров: 5075
Proc 3 Просмотров: 5181
Proc 4 Просмотров: 4338
Proc 5 Просмотров: 3408
Proc 6 Просмотров: 4660
Proc 7 Просмотров: 3927
Proc 8 Просмотров: 3027
Proc 9 Просмотров: 3158
Proc 10 Просмотров: 2918
Proc 11 Просмотров: 3020
Proc 12 Просмотров: 2217
Proc 13 Просмотров: 2455
Proc 14 Просмотров: 2698
Proc 15 Просмотров: 1899
Proc 16 Просмотров: 2885
Proc 17 Просмотров: 2531
Proc 18 Просмотров: 2446
Proc 19 Просмотров: 2365
Proc 20 Просмотров: 3227
Proc 21 Просмотров: 3335
Proc 22 Просмотров: 2453
Proc 23 Просмотров: 2439
Proc 24 Просмотров: 1695
Proc 25 Просмотров: 2079
Proc 26 Просмотров: 1843
Proc 27 Просмотров: 2056
Proc 28 Просмотров: 1764
Proc 29 Просмотров: 1949
Proc 30 Просмотров: 2485
Proc 31 Просмотров: 1701
Proc 32 Просмотров: 1262
Proc 33 Просмотров: 1303
Proc 34 Просмотров: 1722
Proc 35 Просмотров: 1196
Proc 36 Просмотров: 1660
Proc 37 Просмотров: 1513
Proc 38 Просмотров: 1225
Proc 39 Просмотров: 1124
Proc 40 Просмотров: 1868
Proc 41 Просмотров: 1928
Proc 42 Просмотров: 1176
Proc 43 Просмотров: 1147
Proc 44 Просмотров: 1033
Proc 45 Просмотров: 1166
Proc 46 Просмотров: 1067
Proc 47 Просмотров: 1103
Proc 48 Просмотров: 854
Proc 49 Просмотров: 1072
Proc 50 Просмотров: 2115
Proc 51 Просмотров: 1710
Proc 52 Просмотров: 1734
Proc 53 Просмотров: 1207
Proc 54 Просмотров: 1289
Proc 55 Просмотров: 1187
Proc 56 Просмотров: 1770
Proc 57 Просмотров: 1536
Proc 58 Просмотров: 1216
Proc 59 Просмотров: 1132
Proc 60 Просмотров: 1432

Комментарии

Чтобы написать комментарии вам нужно войти в систему или зарегистрироваться



Заявка на расчет