Input output sample - 05

Input Specification:
Input file consists of several test cases. First line of each test case contains an integer n. Followed by a line contains n integers which are the age of n students.

Output Specification:
For each test case print a line contains two integers Maximum  and Minimum Age among them.The Two age are separated by a single space.

Sample Input:
5
10 12 8 13 20
3
7 8 9

Sample Output:
8 20
7 9


Pascal Code:
program sample05 (input, output);

var n,age,max_age,min_age : integer;

begin
    while not eof(input) do begin
        readln(n);
        read(age);
        min_age:=age;
        max_age:=age;
        n:=n-1;
        while n>0 do begin
            read(age);
            if age<min_age then min_age:=age;
            if age>max_age then max_age:=age;
            n:=n-1;
        end;
        writeln(min_age,' ',max_age);
    end;
end.


C Code:
#include <stdio.h>

int main(){
    int n,age,max_age,min_age;
    while(scanf("%d",&n)==1){
        scanf("%d",&age);
        min_age=max_age=age;
        n--;
        while(n--){
            scanf("%d",&age);
            if(age<min_age)
                min_age=age;
            if(age>max_age)
                max_age=age;
        }
        printf("%d %d\n",min_age,max_age);
    }
    return 0;
}


C++ Code:
#include <iostream>

using namespace std;

int main(){
    int n,age,max_age,min_age;
    while(cin>>n){
        cin>>age;
        min_age=max_age=age;
        n--;
        while(n--){
            cin>>age;
            if(age<min_age)
                min_age=age;
            if(age>max_age)
                max_age=age;
        }
        cout<<min_age<<" "<<max_age<<endl;
    }
    return 0;
}


Java Code:
import java.util.*;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n,age,min_age,max_age;
        while(sc.hasNext()){
            n=sc.nextInt();
            age=sc.nextInt();
            min_age=age;max_age=age;
            while(n>1){
                age=sc.nextInt();
                if(age<min_age) min_age=age;
                if(age>max_age) max_age=age;
                n--;
            }
            System.out.println(min_age+" "+max_age);
        }
    }
}