比较输入数字与随机数组首元素大小

#include “stdafx.h”

#include <string>

#include <iostream>

#include <ctime>

#include <cstdlib>

using namespace std;

/ run this program using the console pauser or add your own getch, system(“pause”) or input loop /

int myCompare(const int j, const int a[]);

int main(int argc, char** argv) {

srand(( unsigned)time(NULL ));

int a[10];

for (auto &i : a)

i = rand() % 10;

cout << “enter a number:” << endl;

int j;

cin >> j;

cout << “您输入的数与数组首元素中较大的是:” << myCompare(j, a) << endl;

cout << “数组的全部元素是:” << endl;

for (auto i : a)

cout << i << ‘ ‘;

cout << endl;

return 0;

}

int myCompare(const int j, const int *a)

{

return (j > a) ? j : a;

}