Home / Programs / C Program to Find Smallest Element in Array in C Programming
🚀 Programming Example

C Program to Find Smallest Element in Array in C Programming

👁 1,197 Views
💻 Practical Program
📘 Step Learning
C Program to Find Smallest Element in Array in C Programming

💻 Program Code

#include<stdio.h>

int main() {
   int a[30], i, num, smallest;

   printf("\nEnter no of elements :");
   scanf("%d", &num);

   //Read n elements in an array
   for (i = 0; i < num; i++)
      scanf("%d", &a[i]);

   //Consider first element as smallest
   smallest = a[0];

   for (i = 0; i < num; i++) {
      if (a[i] < smallest) {
         smallest = a[i];
      }
   }

   // Print out the Result
   printf("\nSmallest Element : %d", smallest);

   return (0);
}
                        

🖥 Program Output

Enter no of elements : 5
11 44 22 55 99
Smallest Element : 11
                            

📘 Explanation

none
📚 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.