0% found this document useful (0 votes)
28 views3 pages

Array 1 D

The document contains 3 C++ code snippets that process arrays. The first snippet takes an array as input, filters out non-prime and even elements, and stores them in a new array. The second snippet takes an array as input but has an error in counting elements. The third snippet takes two arrays as input, filters out the even elements from each, and combines them into a new array.

Uploaded by

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

Array 1 D

The document contains 3 C++ code snippets that process arrays. The first snippet takes an array as input, filters out non-prime and even elements, and stores them in a new array. The second snippet takes an array as input but has an error in counting elements. The third snippet takes two arrays as input, filters out the even elements from each, and combines them into a new array.

Uploaded by

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

1.

#include<iostream>
using namespace std;
int main(){
int i,n;

cout<<"Enter the size of the array :";


cin>>n;
int arr[n];
if (n>5)
{

cout<<"Enter "<<n<< " elements in an array"<<endl;


for (int i = 0; i < n; i++)
{
cin>>arr[i];
}
}
else{
cout << "Array size should be greater than 5." << endl;
return 1;
}
int newarr[n];
int count=0;
for(int i =0 ;i<n;i++){

if (arr[i] != 1 && arr[i] % 2 == 0)


{
newarr[count] = arr[i];
count++;
}
}
cout<<"Non-prime elements array"<<endl;
for(int i=0 ;i<count;i++){

cout<<newarr[i]<<" ";

}
cout << endl;

return 0;
}

2.
#include<iostream>
using namespace std;
int main(){
int Array_1[12];
cout<<"Enter 12 element :"
for(int i=0 ;i<=12;i++){
cin>>Array_1[i];
}
int count[12]=0;
for (int i = 0;i < 12; i++) {
if(Array_1[i]==count[12])

return 0;
}

3.

#include<iostream>
using namespace std;
int main(){
int n,m;

cout<<"Enter the size of the array1:";


cin>>n;
if (n<=5)
{
cout << "Array size should be greater than 5." << endl;
return 1;
}
int arr1[n];
cout<<"Enter "<<n<< " elements in an array1"<<endl;
for (int i = 0; i < n; i++)
{
cin>>arr1[i];
}
cout<<"Enter the size of the array2:";
cin>>m;
if (m<=5)
{
cout << "Array size should be greater than 5." << endl;
return 1;
}
int arr2[m];
cout<<"Enter "<<m<< " elements in an array2"<<endl;
for (int i = 0; i < m; i++)
{
cin>>arr2[i];
}
int newarr[n + m];
int count = 0;
for(int i =0 ;i<n;i++){

if (arr1[i]% 2 == 0)
{
newarr[count] = arr1[i];
count++;
}
}

for(int i =0 ;i<m;i++){

if (arr2[i]% 2 == 0)
{
newarr[count] = arr2[i];
count++;
}
}
cout<<"New even elements array :"<<endl;
for(int i=0 ;i<count;i++){

cout<<newarr[i]<<" ";

}
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