Advertisement
Balda

Функции и циклы

Jan 9th, 2014
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <Windows.h>
  3. using namespace std;
  4.  
  5. int EuclidsAlgorithm(int m, int n);
  6. float Count(float a, int n);
  7.  
  8. int EuclidsAlgorithm(int m, int n)
  9. {
  10.     int r;
  11.     while (n != 0)
  12.     {
  13.         r = m % n;
  14.         m = n;
  15.         n = r;
  16.     }
  17.     return m;
  18. }
  19.  
  20. float Count(float a, int n)
  21. {
  22.     float Sum = 1 / a;
  23.     for (int i = 2; i < 2*n; i+=2)
  24.     {
  25.         Sum += 1 / pow(a, i);
  26.     }
  27.     return Sum;
  28. }
  29.  
  30. int main()
  31. {
  32.     SetConsoleCP(1251);
  33.     SetConsoleOutputCP(1251);
  34.     int m1, n1, m, n, result;
  35.     float a;
  36.     cout << "Введите два числа больших нуля" << endl;
  37.     cout << "1 число: ";
  38.     cin >> m;
  39.     cout << "2 Число: ";
  40.     cin >> n;
  41.     m1 = m, n1 = n;
  42.     result = EuclidsAlgorithm(m, n);
  43.     cout << "НОД(" << m1 << "," << n1 << ") = " << result << endl;
  44.     cout << "НОК(" << m1 << "," << n1 << ") = " << (m1*n1) / result << endl;
  45.     cout << "a: ";
  46.     cin >> a;
  47.     cout << "n: ";
  48.     cin >> n;
  49.     cout << Count(a, n) << endl;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement