Advertisement
gha890826

Find the maximum by function

Mar 26th, 2019
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. // ConsoleApplication1.cpp : 定義主控台應用程式的進入點。
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include<iostream>;
  6. using namespace std;
  7.  
  8.  
  9. int maxf(int *in,int n)
  10. {
  11.     int max = in[0];
  12.     for (int i = 0; i < n; i++)
  13.     {
  14.         if (in[i]>max)
  15.             max = in[i];
  16.         cout << "number " << i + 1 << " : ";
  17.         cout << in[i] << endl;
  18.     }
  19.     return max;
  20. }
  21.  
  22. void main()
  23. {
  24.     int n;
  25.     cout << "How maney number you want find:";
  26.     while (cin >> n)
  27.     {
  28.         int *in = new int[n],max;
  29.         for (int i = 0; i < n; i++)
  30.         {
  31.             cout << "number " << i + 1 << " : ";
  32.             cin >> in[i];
  33.         }
  34.         cout << '\n';
  35.         cout << "the maximum is " << maxf(in,n) << endl;
  36.  
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement