1-5-05: The element maximum span value for an integer sequence

Source: Internet
Author: User


Given a sequence of non-negative integers of length n, calculate the maximum span value of a series (maximum span value = maximum value minus minimum value).

Enter a total of 2 rows, the number of the first action sequence N (1 <= n <= 1000), the second behavior sequence of n not more than 1000 non-negative integers, the integers are separated by a space. An output line that represents the maximum span value of the sequence. Sample input

63 0 8 7 5 9

Sample output


Source adapted from Yuanpei-from WHF

#include <stdio.h>intMain () {intn,i,x,max=-1, min=99999, L; scanf ("%d",&N);  for(i=1; i<=n;i++) {scanf ("%d",&x); if(max<x) Max=x; //find the maximum value        if(min>x) Min=x; //Find minimum Value} L=max-min; printf ("%d", L); return 0;}

1-5-05: The element maximum span value for an integer sequence

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.