C++刷题——2736: 指针练习--输出最大值

来源:互联网 发布:数据库调用函数 编辑:程序博客网 时间:2024/06/05 20:36

Description
采用指针法,输出10个整型数中的最大值和最小值

Input
10个整数

Output
最大值和最小值

Sample Input
2 6 3 8 1 5 7 0 4 9
Sample Output
max=9
min=0

 

/* Copyright (c) 2014, 烟台大学计算机学院 * All rights reserved. * 文件名称:test.cpp * 作者:陈丹妮 * 完成日期:2015年 6 月 1 日 * 版 本 号:v1.0 */#include <iostream>using namespace std;int main(){    int a[10],i,max,min,*p;    p=a;    for(i=0; i<10; i++)        cin>>*p++;    max=min=a[0];    for(p=a; p<a+10; p++)    {        if(*p>max)            max=*p;        if(*p<min)            min=*p;    }    cout<<"max="<<max<<endl;    cout<<"min="<<min<<endl;    return 0;}


学习心得:终于复习到指针了,好开心,加油加油,继续努力!!

0 1
原创粉丝点击