3-Arrays 1
3-Arrays 1
int x[5];
Arrays
Initializing Arrays :
OR
x[0] = 5;
x[1] = 20 + x[0];
int y = x[0];
return 0;
}
Arrays
Accessing the values of an array using loops:
#include <iostream>
using namespace std;
int main() {
int x[10];
for(int i = 0; i < 10; i++){
cin >> x[i];
}
char name1[4];
name1[0] = 'A';
name1[1] = 'l';
name1[2] = 'i';
char name5[4];
cin >> name5;
char name4[4];
1 2 3
4 5 6
7 8 9
#include <iostream>
using namespace std;
int main() {
int a[2][3];
int a[2][3] = {
{1, 2, 3},
{4, 5, 6}
};
#include <iostream>
using namespace std;
int main() {
int a[2][3];
*******
* *
* *
* *
* *
* *
*******
● Write a program that takes 2D array of integer of size (N x N) and replace each
even number with (0) and each odd number with (1) and print the 2D array.
Problems
● You and your friend are lost in 2D array and you want to know
the minimum distance between yours, you know your index
(x1, y1) and your friend`s index (x2, y2), what is distance
between yours ?