Monday, February 17, 2014

program to find minimum number in subarrays for the given arrays

in this program, the first input line contains the number of elements in the array,and the second line contains the elements of the array and third line contains number of the sub-arrays ,based on the number of the sub-arrays we are gonna give starting and ending position of the sub-array so that we find the minimum number in that sub-array.The program is
#include<stdio.h>
int main()
{
int a[100];
int b[100];
int mini[100];
int i,c,d,j,min;
long n,m;
int k=0;
scanf("%ld",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
scanf("%ld",&m);
for(i=0;i<m;i++)
{
scanf("%d",&c);
scanf("%d",&d);
min=a[c-1];
for(j=c;j<=d-1;j++)
{
if(min>a[j])
{
min=a[j];
}

}
mini[k]=min;
k=k+1;
}
for(i=0;i<k;i++)
{
printf("%d\n",mini[i]);
}
return 0;
}

output:

5
4 3 8 5 7
2
1 3
3 5
the output is the
3
5
the screenshot of output is the


No comments:

Post a Comment