-
-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathswap_kth_Element.cpp
More file actions
45 lines (32 loc) · 643 Bytes
/
swap_kth_Element.cpp
File metadata and controls
45 lines (32 loc) · 643 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
40
41
42
43
44
45
#include<iostream>
using namespace std ;
void takeInput(int a[], int n){
for(int i=1;i<=n;i++){
cin>>a[i];
}
}
void swap_k(int a[], int n, int k){
int i , count = n ;
for(i=1 ; i<=n , count >= 1 ; i++ , count--){
if(k == i || k == count){
swap(a[k],a[count]);
}
}
for(i=1;i<=n;i++){
cout<<a[i]<<" " ;
}
}
int main()
{
int n;
cout<<"Enter size of an Array:";
cin>>n ;
int k;
cout<<"Enter Kth element to swap:";
cin>>k ;
int a[1000];
takeInput(a,n);
swap_k(a,n,k);
cout<<"\n";
return 0;
}