Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions Find the largest and smallest number
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/* Program to find the largest and smallest number in an array */

#include <stdio.h>
int main()
import java.util.*;
public class Xyz
{
int i, arr[10] = {2, 5, 4, 1, 8, 9, 10, 6, 3, 7};
long int small, large;
small = large = arr[0];
for(i=1; i<10; i++)
{
if(arr[i] < small)
small = arr[i];
if(arr[i] > large)
large = arr[i];
}
printf("Smallest = %d, Largest = %d\n", small, large);
public static void main (String args[])
{
int [] arr={1,3,6,8,7,-6,-8,0,3};
System.out.println("Smalest And Largest Number Are");
System.out.println(Arrays.toStrings(lagest&smallest(arr)));
}
public static int[] lagest&smallest(int arr[])
{
Arrays.sort(arr);
int arr1[]= new int[2];
arr1[0]=arr[0];
arr1[1]=arr[arr.length-1];
return arr1;
}
}