#include <stdio.h>
int main()
{
int a,b[10],i,max=0,min=100;
scanf("%d",&a);
for(i=0;i<a;i++)
{
scanf("%d",&b[i]);
}
for(i=0;i<a;i++)
{
if(min>b[i]) { min=b[i];}
if(max<b[i]) { max=b[i];}
}
printf("Minimum element in an array : %d\n",min);
printf("Maximum element in an array : %d",max);
return 0;
}
- Problem Description
Given a list of N integers, your task is to find out the miniumum and maximum.
Input Format:
No.of integers and the integers
- Test Case 1
Input (stdin) 5
2 3 1 6 7
Expected OutputMinimum element in an array : 1
Maximum element in an array : 7
- Test Case 2
Input (stdin)6
11 2 10 6 5 1
Expected OutputMinimum element in an array : 1
Maximum element in an array : 11
#include
ReplyDelete#include
using namespace std;
int main()
{
int n;
cin>>n;
int k;
cin>>k;
int arr[n];
for(int i =0;i>arr[i];
int unfairness = INT_MAX;
sort(arr,arr+n);
for (int i = 0; i < n - k + 1; i++){
if (arr[i+k-1]-arr[i]<unfairness)
unfairness = arr[i+k-1]-arr[i];
}
cout<<unfairness;
return 0;
}