Display Smallest Element of an array
C Programming Language Array in C Language (Article) Array in C Language (Program)
1067Program:
/* 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; }
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
This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.