-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsorting.c
More file actions
46 lines (38 loc) · 1.09 KB
/
sorting.c
File metadata and controls
46 lines (38 loc) · 1.09 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* @file sorting.c
* 46. Write a program to sort an array in ascending order and find the 3rd largest element in array.
* @author Md. Alamin (alamin5g@yahoo.com)
* I would love be a software engineer at Google. That is why anybody can uses this code without any condition, if you face any difficulty, then try to email me.
* @version 0.1
* @date 2022-03-15
*
* @copyright Copyright (c) 2022
*
*/
#include <stdio.h>
void main(){
int arr[10], i, next,temp, nTime;
printf("How many array elements: ");
scanf("%d", &nTime);
printf("\nEnter %d elements: \n",nTime);
for(i=0; i<nTime; i++){
scanf("%d", &arr[i]);
}
for ( i = 0; i < nTime; i++)
{
for(next = i+1; next<nTime; next++){
if (arr[i]>arr[next])
{
temp = arr[i];
arr[i] = arr[next];
arr[next] = temp;
}
}
}
printf("Array sorted in Asscending Order: ");
for (i = 0; i < nTime; i++)
{
printf("%d\t", arr[i]);
}
printf("\n%d is the 3rd largest", arr[nTime-3]);
}