Program to find the smallest element in the given array in C programming language

 Program to find the smallest element in the given array:


#include<stdio.h>

int main()

{

int i,n,arr[20],pos,small;

printf("enter no of element in array \n");

scanf("%d",&n);

printf("array element are =\n");

for(i=0;i<n;i++)

{

printf("\n arr[i]= ",i);

scanf("%d",&arr[i]);

}

small=arr[0];

pos=0;

for(i=0;i<n;i++)

{

if(arr[i]<small)

{

small=arr[i];

pos=i;

}

}

printf("Smallest number in the array is %d\n",small);

printf("  Position of the element is %d",pos);

}

output:

enter number of elements in array:3

12

33

2

smallest element in array is 2.


Comments