指针数组

问题描述:
用指针完成数组的赋值,输出,求最大值,最小值

#include<iostream>
#include<stdlib.h>
#include<time.h>

int main(void){
	int *p,a[10],max,min;
	srand(time(NULL));
	for(p=a;p<=a+9;p++)
		*p=rand()%90+10;
	cout<<"数组元素为:"<<endl;
	for(p=a;p<=a+9;p++)
		std::cout<<*p<<' ';
	std::cout<<std::endl;
	max=a[0];
	min=a[0];
	for(p=a;p<=a+9;p++)
		if(max<*p)
			max=*p;
		if(min>*p)
			min=*p;
	std::cout<<"max:"<<max<<std::endl;
	std::cout<<"min:"<<min<<std::endl;	
} 

运行结果:

posted @ 2019-04-14 22:37  天真王二小  阅读(58)  评论(0编辑  收藏  举报