Home / Programs / Display Smallest Element of an array
🚀 Programming Example

Display Smallest Element of an array

👁 1,142 Views
💻 Practical Program
📘 Step Learning
Display Smallest Element of an array

💻 Program Code

 /*
Display Smallest Element of an array
 Author: atnyla Developer
 */

  
#include"stdio.h"

int main()
{
    int i, n;
    float arr[100];

    printf("Enter total number of elements(1 to 100): ");
    scanf("%d", &n);
    printf("\n");

    // Stores number entered by the user
    for(i = 0; i < n; ++i)
    {
       printf("Enter Number %d: ", i+1);
       scanf("%f", &arr[i]);
    }

    // Loop to store largest number to arr[0]
    for(i = 1; i < n; ++i)
    {
       // Change < to > if you want to find the smallest element
       if(arr[0] > arr[i])
           arr[0] = arr[i];
    }
    printf("Largest element = %.2f \n", arr[0]);

    return 0;
}
                        

🖥 Program Output

Enter total number of elements(1 to 100): 5

Enter Number 1: 1
Enter Number 2: 2
Enter Number 3: 3
Enter Number 4: 4
Enter Number 5: 5
Largest element = 1.00
Press any key to continue . . .
                            

📘 Explanation

Display Smallest Element of an array
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.