Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- {
- int n,i,j,temp,a[100];
- printf("Enter the number of elements: ");
- x: scanf("%d",&n);
- if(n<2)
- {
- printf("No. of elements must be greater than 1: ");
- goto x;
- }
- printf("Enter %d elements.\n",n);
- for(i=0; i<n; i++)
- scanf("%d",&a[i]);
- for(i=0;i<n-1;i++)
- {
- for(j=0; j<n-i-1; j++)
- {
- if(a[j]>a[j+1])
- {
- temp = a[j];
- a[j] = a[j+1];
- a[j+1] = temp;
- }
- }
- }
- printf("Second-Smallest number is %d",a[1]);
- printf("\nSecond-Largest number is %d",a[n-2]);
- fflush(stdin);
- getchar();
- return 0;
- }
- //Output
- //Now enter 5 elements:-
- //1
- //2
- //3
- //4
- //5
- //Second Smallest number is 2
- //Second Largest is 4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement