-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path16.cpp
More file actions
82 lines (63 loc) · 1.26 KB
/
16.cpp
File metadata and controls
82 lines (63 loc) · 1.26 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
@Author: Amritanshu Sikdar
Session: 2018-'19
Repository: https://github.com/amritanshusikdar/CS30PracticalQuestion
*/
// Program to swap odd places of 2 arrays
#include <constream.h>
void input(int*, int*);
void transfer(int*, int*);
void display(int*, int*);
void main()
{
clrscr();
int a[6], b[6];
input(a,b);
transfer(a,b);
cout << "\nAfter Swapping odd places:- \n";
display(a,b);
getch();
}
void input(int a[6], int b[6])
{
int i;
cout << "Input in first array!" << endl;
for(i=0; i<6; i++)
{
cout << "A[" << i << "]: ";
cin >> a[i];
}
cout << "Input in second array!" << endl;
for(i=0; i<6; i++)
{
cout << "B[" << i << "]: ";
cin >> b[i];
}
}
void transfer(int a[6], int b[6])
{
int i, temp;
for(i=0; i<6; i++)
{
if(i % 2 == 1)
{
temp = a[i];
a[i] = b[i];
b[i] = temp;
}
}
}
void display(int a[6], int b[6])
{
int i;
cout << "First array!" << endl;
for(i=0; i<6; i++)
{
cout << "A[" << i << "]: " << a[i] << endl;
}
cout << "Second array!" << endl;
for(i=0; i<6; i++)
{
cout << "B[" << i << "]: " << b[i] << endl;
}
}