-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.cpp
60 lines (41 loc) · 1020 Bytes
/
1.cpp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
@Author: Amritanshu Sikdar
Session: 2018-'19
Repository: https://github.com/amritanshusikdar/CS30PracticalQuestion
*/
// Program to swap every even with following odd location of an integer array
#include<iostream.h>
#include<conio.h>
#define size 10
void oddEvenSwap(int*, int);
int main()
{
clrscr();
int array[size] = {1,2,3,4,5,6,7,8,9,10}, i;
cout << "Original array: " << endl;
for(i=0; i < size; i++)
{
cout << "A[" << i << "]:" << *(array+i) << endl;
}
oddEvenSwap(array, size);
cout << "Swapped array: " << endl;
for(i=0; i < size; i++)
{
cout << "A[" << i << "]:" << *(array+i) << endl;
}
getch();
return 0;
}
void oddEvenSwap(int *array, int limit)
{
int i=0, check=1, temp;
while(i < limit && check == 1)
{
temp = *(array+i);
*(array+i) = *(array+i+1);
*(array+i+1) = temp;
i += 2;
if(limit % 2 != 0 && i == limit-1)
check = -1;
}
}