Advertisement
AedenCak3

C program to print second largest and second smallest value in

Dec 9th, 2021
844
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. #include<stdio.h>
  2. #include <ctype.h>
  3. #include <string.h>
  4.  
  5. int main()
  6. {
  7.     int i,a,j, counter;
  8.  
  9.     printf("Enter the size of array: ");
  10.     scanf("%d",&a);
  11.  
  12.     int arr[a];
  13.     for (i=0; i<a; i++)
  14.     {
  15.         scanf("%d",&arr[i]);
  16.     }
  17.     for( i=0; i<a; i++)
  18.     {
  19.         for(j=i+1; j<a; j++)
  20.         {
  21.             if (arr[i]>arr[j])
  22.             {
  23.                 counter=arr[i];
  24.                 arr[j]=counter;
  25.                 arr[i]=arr[j];
  26.             }
  27.         }
  28.     }
  29.  
  30.     printf("The second largest value is : %d\n",arr[a-2]);
  31.    
  32.     printf("The second smallest value is : %d\n", arr[1]);
  33.  
  34.     return 0;
  35.  
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement