По разделам

 

Решение задачи 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 Просмотров: 5073
Proc 3 Просмотров: 5180
Proc 4 Просмотров: 4338
Proc 5 Просмотров: 3408
Proc 6 Просмотров: 4659
Proc 7 Просмотров: 3927
Proc 8 Просмотров: 3027
Proc 9 Просмотров: 3158
Proc 10 Просмотров: 2917
Proc 11 Просмотров: 3017
Proc 12 Просмотров: 2215
Proc 13 Просмотров: 2454
Proc 14 Просмотров: 2697
Proc 15 Просмотров: 1899
Proc 16 Просмотров: 2885
Proc 17 Просмотров: 2527
Proc 18 Просмотров: 2445
Proc 19 Просмотров: 2365
Proc 20 Просмотров: 3226
Proc 21 Просмотров: 3334
Proc 22 Просмотров: 2453
Proc 23 Просмотров: 2438
Proc 24 Просмотров: 1693
Proc 25 Просмотров: 2076
Proc 26 Просмотров: 1842
Proc 27 Просмотров: 2055
Proc 28 Просмотров: 1764
Proc 29 Просмотров: 1949
Proc 30 Просмотров: 2485
Proc 31 Просмотров: 1700
Proc 32 Просмотров: 1262
Proc 33 Просмотров: 1303
Proc 34 Просмотров: 1721
Proc 35 Просмотров: 1196
Proc 36 Просмотров: 1660
Proc 37 Просмотров: 1513
Proc 38 Просмотров: 1223
Proc 39 Просмотров: 1124
Proc 40 Просмотров: 1868
Proc 41 Просмотров: 1927
Proc 42 Просмотров: 1176
Proc 43 Просмотров: 1145
Proc 44 Просмотров: 1033
Proc 45 Просмотров: 1166
Proc 46 Просмотров: 1067
Proc 47 Просмотров: 1103
Proc 48 Просмотров: 854
Proc 49 Просмотров: 1072
Proc 50 Просмотров: 2114
Proc 51 Просмотров: 1708
Proc 52 Просмотров: 1734
Proc 53 Просмотров: 1206
Proc 54 Просмотров: 1289
Proc 55 Просмотров: 1186
Proc 56 Просмотров: 1769
Proc 57 Просмотров: 1534
Proc 58 Просмотров: 1216
Proc 59 Просмотров: 1130
Proc 60 Просмотров: 1430

Комментарии

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



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