Second Smallest Number (Id-1242)
Just for Practice 1 Additional [3-Jan-2018 to 10-Apr-2018]
CSE1002 Bonus Practice Sheet Winter 2018 [17-Mar-2018 to 7-Apr-2018]
Given a set of elements, design an Algorithm and write the subsequent C program to determine the second smallest number in that set.
Input Format
Number of elements in ‘n’
element-1
element-2
…
element-n
Output Format
Second smallest element in the set
Please Comment Working if the code worked to you
If you have other working codes please comment the codes enclosing with <pre> and </pre> 🙂
Example: <pre> Your Code </pre>
C Code [By Chir Patel]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include<stdio.h> #include<string.h> int main() { int n; scanf("%d",&n); int arr[n],i,j,k; for(i=0;i<n;i++) { scanf("%d",&arr[i]); } for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(arr[i]>arr[j]) { k=arr[j]; arr[j]=arr[i]; arr[i]=k; } } } printf("%d",arr[1]); } |