Monday, 12 December 2016

How to Find Maximum & Minimum Element in the Array Program in C

  1. #include<stdio.h>  
  2. # include<conio.h>  
  3. void main()  
  4. {  
  5. int a[100],i,n,max,min;  
  6. clrscr();  
  7. printf("How many elements in the array : ");  
  8. scanf("%d",&n);  
  9. printf("Enter the elements : \n");  
  10.   for(i=0;i<=n-1;i++)  
  11.     {  
  12.      scanf("%d",&a[i]);  
  13.     }  
  14. max = a[0];  
  15. min = a[0];  
  16.   for(i=1;i<=n-1;i++)  
  17.    {  
  18.     if(max<a[i])  
  19.     max = a[i];  
  20.    if(min>a[i])  
  21.    min = a[i];  
  22.   }  
  23. printf("maximum element in the array is :%d\n ",max);  
  24. printf("minimum element in the array is : %d\n",min);  
  25. getch();  
  26. }  

No comments:

Post a Comment

STEPS TO SAVE YOUR EYES WHILE WORKING ON COMPUTER

STEPS TO SAVE YOUR EYES WHILE WORKING ON COMPUTER This is the report for all you people who works more and more on computer for long t...