C Program To Find Smallest Element In An Array

preview_player
Показать описание

Lets write a C program to find smallest element in an array, without sorting the elements. And also print the position at which the smallest number is present in the array.

Example: Expected Output
Enter 5 integer numbers
5
2
6
4
3

Biggest of 5 numbers is 2, at position 2.

C Programming Interview / Viva Q&A List

C Programming: Beginner To Advance To Expert
Рекомендации по теме
Комментарии
Автор

Im from 🇱🇰. Well explanation. Thankyou!

Danie.d
Автор

I was looking for a way to get the position of that element and you taught it so well, Many Thanks! Also you have a nice blog on programming too👌

nitishnagar
Автор

Anna please can you please post videos regarding alphabetical array sorting program

kaviyabalasundaram
Автор

It is well & so clear sir,
But could u able to explain in telugu?.

muralaprasannakumar
Автор

THIS IS TO FIND 2ND LARGEST ELEMENT IN IN ARRAY

#include <stdio.h>
int main()
{ //Creation and printing of array
int elements;
printf("Total elements : ");
scanf("%d", &elements);
int array[elements];
inputarray(array, elements);
spc();
printarray(array, elements);

//Finding maximum element
int max=array[0];
for(int i=0;i<elements;i++)
{
if(array[i]>max)
{
max=array[i];
}
}

//Finding 2nd largest element
int diffmax2=max-array[0], max2;
for(int j=0;j<elements;j++)
{
int diff=max-array[j];
if(diff<diffmax2 && diff!=0)
{
diffmax2=diff;
max2=array[j];
}
}
spc();
printf("The second largest element is = %d", max2);
}

RahulSharma-jzqi