#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main(){
srand
(time(NULL));
int
a;
int
array[6];
int
*b = array;
for(int
i=0;i<6;i++){
a
= rand() % 20 + 1;
array[i]=a;
for(int
j=0;j<i;j++){
if
(array[i]==array[j]){
i--;
break;}
}
}
cout<<"陣列裡面的數字:";
for(int
i=0;i<6;i++){
cout<<*(b+i)<<"
";}
cout<<endl;
cout<<"請輸入一個整數(1~20之間):";
int
c;
cin>>c;
if ((*(array) == c)||(*(array+1) ==
c)||(*(array+2) == c)||(*(array+3) == c)||
(*(array+4) == c)||(*(array+5) == c))
cout << "數字 " << c << " 存在於此陣列中"
<< endl;
else
cout << "數字 " << c << " 不存在此陣列中"
<< endl;
沒有留言:
張貼留言