-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndexed_Sort.c
More file actions
39 lines (37 loc) · 778 Bytes
/
Copy pathIndexed_Sort.c
File metadata and controls
39 lines (37 loc) · 778 Bytes
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
#include<stdio.h>
//SORT THOSE INDEXED ELEMENT WHICH ARE DIVISIBLE BY K//
int main()
{
int n,k;
printf("Enter the length of the array:");
scanf("%d",&n);
int arr[n];
printf("Enter the elements:");
for(int i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
printf("Enter the value of k:");
scanf("%d",&k);
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(i%k==0 &&j%k==0)
{
if(arr[i]>arr[j])
{
int temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
}
printf("Output will be");
for(int i=0;i<n;i++)
{
printf("%d ",arr[i]);
}
return 0;
}