0% found this document useful (0 votes)
6 views

2 dimentional array examples pf

The document contains C++ code examples demonstrating the use of 2-dimensional arrays. The first example searches for a user-input integer in a 3x3 array and reports its location if found. The second and third examples iterate through 2x2 arrays to identify and print even numbers along with their respective locations.

Uploaded by

Daud Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

2 dimentional array examples pf

The document contains C++ code examples demonstrating the use of 2-dimensional arrays. The first example searches for a user-input integer in a 3x3 array and reports its location if found. The second and third examples iterate through 2x2 arrays to identify and print even numbers along with their respective locations.

Uploaded by

Daud Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

// 2 dimentional array examples

#include<iostream>
using namespace std;
int main()
{
int arr[3][3] = {{1,2,4},{4,6,8},{4,20,30}};
int search,count = 0;
cout<<"enter int value to search"<<endl;
cin>>search;
for(int r = 0;r<=2;r++)
{
for(int c=0;c<=2;c++)
{
//cout<<arr[r][c]<<"\t";
if(arr[r][c] == search)
{
cout<<"value found "<<arr[r][c]<<" at
location "<<r<<c;
count++;
}

}
cout<<endl;
}
if(count == 0)
cout<<"not found "<<search<<endl;
return 0;
}

Example No 2..

#include<iostream>
using namespace std;
int main()
{
int arr[2][2] = {{1,2},{10,20}};
for(int r = 0;r<=2;r++)
{
for(int c=0;c<=2;c++)
{
//cout<<arr[r][c]<<"\t";
if(arr[r][c]%2 == 0)
{
cout<<"Even number "<<arr[r][c]<<" at
location "<<r<<c;
//count++;
}

}
cout<<endl;
}
return 0;
}

Example No 3:
#include<iostream>
using namespace std;
int main()
{
int arr[2][2] = {{1,2},{10,20}};
for(int r = 0;r<=1;r++)
{
for(int c=0;c<=1;c++)
{
//cout<<arr[r][c]<<"\t";
if(arr[r][c]%2 == 0)
{
cout<<"Even number "<<arr[r][c]<<" at
location "<<r<<c<<endl;
//count++;
}

}
//cout<<endl;
}
return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy