C language · Second largest integer

Source: Internet
Author: User

Algorithm to increase the second large integer time limit: 1.0s memory limit: 512.0MBThe problem description writes a program that reads in a set of integers (no more than 20), and when the user enters 0 o'clock, the input ends. The program will then find the second largest integer from this set of integers and print it out. Note: (1) 0 indicates the end of the input, which itself is not counted in this set of integers. (2) In this set of integers, both positive and negative numbers are possible. (3) The number of integers in this group is not less than 2.
Input format: Enter only one line, including several integers, separated by a space, the last integer is 0.
Output format: Output the second largest integer.
Input/Output Sample sample input 5 8-12 7 0 Sample Output 7
1#include <stdio.h>2 intMain () {3     inta[ -];4     intk=0;//Array subscript5     intx;6      while(~SCANF ("%d",&x)) {7         if(x==0)8              Break;9         ElseTena[k++]=x; One     } A     /*Bubble Descending*/ -      for(intI=0; i<k-1; i++){ -          for(intj=0; j<k-1-I.; J + +){ the             if(a[j]<a[j+1]){ -                 intt =A[j]; -A[J] = a[j+1]; -a[j+1] =T; +             } -         } +     } Aprintf"%d", a[1]); at}

C language · Second largest integer

Related Article

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.