Skip to content

Commit 5cc3d3e

Browse files
Create List_using_Array_Example_2.c
1 parent 665c0c6 commit 5cc3d3e

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

List_using_Array_Example_2.c

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Students of class CSE are given an array A of positive integers of size N. The student’s task is to sort the array in increasing order and print out the original index position of the newly sorted array.
2+
3+
// NOTE: The indexing of the array starts with 0.
4+
5+
// Example:
6+
7+
// A={4,5,3,7,1}
8+
9+
// After sorting the new array becomes A={1,3,4,5,7}.
10+
11+
// The required output should be "4 2 0 1 3"
12+
13+
// INPUT :
14+
15+
// The first line of input consists of the size of the array A
16+
17+
// The next line consists of the array of size N
18+
19+
// OUTPUT :
20+
21+
// Output consists of a single line of integers
22+
23+
// CONSTRAINTS:
24+
25+
// 1<=N<=10^6
26+
27+
// 0<=A[i]<=10^6
28+
29+
30+
// Sample Input 1
31+
32+
// Input:
33+
34+
// 5
35+
36+
// 12 3 87 14 65
37+
38+
// Output:
39+
40+
// 1 0 3 4 2
41+
42+
// Sample Input 2
43+
44+
// Input:
45+
46+
// 7
47+
48+
// 12 23 32 45 56 67 89
49+
50+
// Output:
51+
52+
// 0 1 2 3 4 5 6
53+
54+
#include<stdio.h>
55+
int main()
56+
{
57+
int n,a[100],b[100],temp;
58+
scanf("%d",&n);
59+
for(int i=0;i<n;i++)
60+
{
61+
scanf("%d",&a[i]);
62+
b[i]=a[i];
63+
}
64+
for(int i=0;i<n;i++)
65+
{
66+
for(int j=i+1;j<n;j++)
67+
{
68+
if(a[i]>a[j]){
69+
temp=a[j];
70+
a[j]=a[i];
71+
a[i]=temp;}
72+
}
73+
}
74+
for(int i=0;i<n;i++)
75+
{
76+
for(int j=0;j<n;j++)
77+
{
78+
if(a[i]==b[j])
79+
printf("%d ",j);
80+
}
81+
}
82+
}

0 commit comments

Comments
 (0)