-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.cpp
54 lines (39 loc) · 928 Bytes
/
2.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
/*
@Author: Amritanshu Sikdar
Session: 2018-'19
Repository: https://github.com/amritanshusikdar/CS30PracticalQuestion
*/
// Program to swap half of the integer array with the other half
#include<iostream.h>
#include<conio.h>
#define size 10
void halfSwap(int*, int);
int main()
{
clrscr();
int i;
int array[size] = {1,2,3,4,5,6,7,8,9,10};
cout << "Original array: " << endl;
for(i=0; i < size; i++)
{
cout << "A[" << i << "]:" << *(array+i) << endl;
}
halfSwap(array, size);
cout << "Swapped array: " << endl;
for(i=0; i < size; i++)
{
cout << "A[" << i << "]:" << *(array+i) << endl;
}
getch();
return 0;
}
void halfSwap(int *array, int limit)
{
int i, j, condition, temp;
for(i=0,j=limit/2; i < limit/2; i++,j++)
{
temp = *(array+i);
*(array+i) = *(array+j);
*(array+j) = temp;
}
}