Chapter:

Arrays-

Write a program in C to find maximum and minimum element in an array.

Write a program in C to find the maximum and minimum element in an array.

#include <stdio.h>

void main()
{
      int arr1[100];
      int i, mx, mn, n;
      printf("\n\nFind maximum and minimum element in an array :\n");
                                            printf("--------------------------------------------------\n");	
       printf("Input the number of elements to be stored in the array :");
       fflush(stdout);
       scanf("%d",&n);
       printf("Input %d elements in the array :\n",n);
       for(i=0;i<n;i++)
            {
            	printf("element - %d : ",i);
	            fflush(stdout);
	            scanf("%d",&arr1[i]);
	         }
       mx = arr1[0];
       mn = arr1[0];
       for(i=1; i<n; i++)
       {
       	if(arr1[i]>mx)
       	{
              mx = arr1[i];
           }
          if(arr1[i]<mn)
  ....
Show More

All Chapters

View all Chapter and number of question available From each chapter from C-programming-