Digital जीवन

Free Online Education for India...

Full width home advertisement

Computer Basic

C Programming

Engineering Graphics

Post Page Advertisement [Top]

Dr. A.P.J. Abdul Kalam Technical University, Lucknow

KCS101 / KCS201 Programming for Problem Solving - Using C Language


Lab Exercises


23. Write a program to find the minimum and maximum elements of the array.


/*
 File: Prgrm23.c
 Author: Aditya Saini
 Date: Sept 30, 2019
 Description: Program to find the minimum and maximum elements of the array.
*/

#include <stdio.h>

int main (void)
{
               int array [10];
               int minimum, maximum;
               int i;

               //Input elements of array
               for (i = 0; i < 10; i++)
               {
                              printf ("Input %d element: ", i + 1);
                              scanf ("%d", &array [i]);
               }

               //Finding the minimum and maximum elements
               minimum = maximum = array [0];
               for (i = 1; i < 10; i++)
               {
                              if (minimum > array [i])
                                             minimum = array [i];
                              else if (maximum < array [i])
                                             maximum = array [i];
               }

               //Output the result
               printf ("\nMinimum element: %d", minimum);
               printf ("\nMaximum element: %d", maximum);

               return 0;
};

Output

Input 1 element: 27
Input 2 element: 46
Input 3 element: 92
Input 4 element: 42
Input 5 element: 80
Input 6 element: 58
Input 7 element: 13
Input 8 element: 22
Input 9 element: 73
Input 10 element: 38

Minimum element: 13
Maximum element: 92



No comments:

Post a Comment

Please do not post spam links.

Bottom Ad [Post Page]

| Designed by Colorlib