BM Balmiki Mandal 08 Apr 2023 1 views 0 comments C Programming

Creating a C Program to Identify Largest and Smallest Numbers in Unsorted Arrays

C Program to Find Largest and Smallest Numbers in Unsorted Array

To design a C program function to print 10 numbers through the keyword into an array and find the biggest and smallest number in an unsorted array without using any sorting technique means to write a function in C programming language that performs the following tasks:

  1. Prompt the user to input 10 numbers through the keyword.
  2. Store the 10 numbers in an array.
  3. Find the largest and smallest number in the array without using any sorting technique.
  4. Print the largest and smallest number to the console.

The function should be designed to take an array of integers as input, perform the above tasks, and return the largest and smallest numbers found in the array as output. The function should not use any built-in sorting functions or techniques to find the largest and smallest numbers in the array. Instead, it should use iterative comparison to determine the maximum and minimum values in the array.

C Program to Find the Maximum and Minimum Number in an Unsorted Array of 10 Elements

#include<stdio.h>

void findMinMax(int arr[], int n)
{
    int i, min, max;
    min = max = arr[0];
    
    for (i = 1; i < n; i++) {
        if (arr[i] < min) {
            min = arr[i];
        }
        if (arr[i] > max) {
            max = arr[i];
        }
    }
    printf("The smallest number in the array is: %d\n", min);
    printf("The largest number in the array is: %d\n", max);
}

int main()
{
    int arr[10], i;
    printf("Enter 10 numbers:\n");
    
    for (i = 0; i < 10; i++) {
        scanf("%d", &arr[i]);
    }
    findMinMax(arr, 10);
    return 0;
}

Explanation

The function findMinMax() takes two arguments, an array arr[] and its size n. In this function, we first initialize min and max with the first element of the array. Then we loop through the array and compare each element with min and max to find the smallest and largest numbers. Finally, we print the values of min and max.

In the main() function, we declare an integer array arr[] of size 10 and prompt the user to input 10 numbers through the keyword. We then call the findMinMax() function and pass the array and its size as arguments.

0 Comments

No comments yet, Be the first to comment.

Post a Comment

Please sign in to post a comment.

Related Posts

Bit wise operators Assignment

Bitwise Operators practical assignment: Take runtime input, bit-level manipulation, and different data units r...

AG Anvesh G 27 Sep 2026
Understanding Float and Double Binary Representation in C

Understanding Float and Double Binary Representation in CIntroduction:When we store decimal numbers such as 10...

AG Anvesh G 31 May 2026
Topic-wise C Programming Interview Questions

C Programming Interview Questions – Topic Wise1. IntroductionC programming is one of the most important langu...

AG Anvesh G 30 May 2026