Location of Minimum Element

QUESTION

Given an array of integers, our task is to write a program that efficiently find the minimum element present in the array and location of the minimum element.

“TESTCASE_1”: “5\n1 2 3 4 0\n###—###SEPERATOR—###—\nMinimum element position=5\nValue=0”, “TESTCASE_2”: “10\n-1 -2 0 1 -1 4 2 5 1 2\n###—###SEPERATOR—###—\nMinimum element position=2\nValue=-2”, “TESTCASE_3”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_4”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0

ANSWER

#include <stdio.h>
int main()
{
int n;
  scanf("%d",&n);
  int i,arr[n],arr2[n];
  for(i=0;i<n;i++)
  {
    scanf("%d",&arr[i]);
    arr2[i]=arr[i];
  }
  int j;
  
    for(j=1;j<n;j++)
    {
      if(arr[0]>arr[j])
      {
        int t=arr[0];
        arr[0]=arr[j];
        arr[j]=t;
      }
    }
  for(i=0;i<n;i++)
      {
        if(arr[0]==arr2[i])
        {
          printf("Minimum element position=%d\nValue=%d",i+1,arr[0]);
          break;
        }
  }
  
        
	return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
CHP Adblock Detector Plugin | Codehelppro