По разделам

 

Решение задачи 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 Просмотров: 6511
Proc 2 Просмотров: 5031
Proc 3 Просмотров: 5115
Proc 4 Просмотров: 4302
Proc 5 Просмотров: 3361
Proc 6 Просмотров: 4606
Proc 7 Просмотров: 3890
Proc 8 Просмотров: 2984
Proc 9 Просмотров: 3123
Proc 10 Просмотров: 2880
Proc 11 Просмотров: 2983
Proc 12 Просмотров: 2180
Proc 13 Просмотров: 2421
Proc 14 Просмотров: 2654
Proc 15 Просмотров: 1865
Proc 16 Просмотров: 2839
Proc 17 Просмотров: 2484
Proc 18 Просмотров: 2405
Proc 19 Просмотров: 2323
Proc 20 Просмотров: 3169
Proc 21 Просмотров: 3296
Proc 22 Просмотров: 2400
Proc 23 Просмотров: 2397
Proc 24 Просмотров: 1658
Proc 25 Просмотров: 2030
Proc 26 Просмотров: 1805
Proc 27 Просмотров: 2005
Proc 28 Просмотров: 1735
Proc 29 Просмотров: 1914
Proc 30 Просмотров: 2444
Proc 31 Просмотров: 1668
Proc 32 Просмотров: 1220
Proc 33 Просмотров: 1248
Proc 34 Просмотров: 1670
Proc 35 Просмотров: 1153
Proc 36 Просмотров: 1612
Proc 37 Просмотров: 1473
Proc 38 Просмотров: 1193
Proc 39 Просмотров: 1097
Proc 40 Просмотров: 1830
Proc 41 Просмотров: 1897
Proc 42 Просмотров: 1148
Proc 43 Просмотров: 1115
Proc 44 Просмотров: 998
Proc 45 Просмотров: 1126
Proc 46 Просмотров: 997
Proc 47 Просмотров: 1058
Proc 48 Просмотров: 810
Proc 49 Просмотров: 1045
Proc 50 Просмотров: 2076
Proc 51 Просмотров: 1681
Proc 52 Просмотров: 1686
Proc 53 Просмотров: 1171
Proc 54 Просмотров: 1258
Proc 55 Просмотров: 1144
Proc 56 Просмотров: 1738
Proc 57 Просмотров: 1488
Proc 58 Просмотров: 1171
Proc 59 Просмотров: 1082
Proc 60 Просмотров: 1364

Комментарии

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



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