0% found this document useful (0 votes)
14 views6 pages

Meditatie 19.10.2023

The document contains code snippets that perform various operations on arrays: 1) Calculate the average of array elements and output elements greater than the average 2) Output elements that equal the sum of the previous and next elements 3) Calculate the sum of even elements 4) Find the maximum negative element 5) Output prime numbers in an array 6) Replace elements that are perfect squares with their square root 7) Remove the minimum element from the array

Uploaded by

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

Meditatie 19.10.2023

The document contains code snippets that perform various operations on arrays: 1) Calculate the average of array elements and output elements greater than the average 2) Output elements that equal the sum of the previous and next elements 3) Calculate the sum of even elements 4) Find the maximum negative element 5) Output prime numbers in an array 6) Replace elements that are perfect squares with their square root 7) Remove the minimum element from the array

Uploaded by

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

Ex 1:

int v[100], i, n;
float medie=0;
cin>>n;
for(i=0;i<n;i=i+1){
cin>>v[i];
}
for(i=0;i<n;i=i+1){
medie=v[i]+medie;
}
medie = medie / n;
for(i=0;i<n;i=i+1){
if(v[i] > medie){
cout<<v[i] << ' ';
}
}

Ex 2:

int v[100],i , n;
cin>>n;
for(i=0;i<n;i=i+1){
cin>>v[i];
}
for(i=1;i<n-1;i=i+1){
if(v[i]==v[i-1]+v[i+1])
cout << v[i] << ' ';
}

Ex 3:

int i, v[100], n,sum=0;


cin>>n;
for(i=0;i<n;i=i+1){
cin>>v[i];
}
for(i=1;i<n;i=i+2){
if(v[i]%2==0){
sum=sum+v[i];
}
}
cout<<sum;

Ex 5:

int v[100] , n , i ,max=-100000;


cin>>n;
for(i=0;i<n;i=i+1){
cin>>v[i];
}
for(i=0;i<n;i=i+1){
if(v[i]<0 && v[i]>max){
max=v[i];
}
}
cout<<max;

Ex: 11

int i,n, v[100],j=0,m,f[100],ok, d;


cin>>n;
for(i=0;i<n;i=i+1){
cin>>v[i];
}
for(i=0;i<n;i=i+1){
ok=1;
if (v[i] == 1 || v[i] == 0)
ok = 0;
for(d=2;d*d<=v[i];d=d+1){
if(v[i]%d==0){
ok=0;
}
}
if(ok==1){
f[j]=v[i];
j=j+1;
}
}
m=j;
for(j=0;j<m;j=j+1){
cout<<f[j]<<" ";
}
int n,i,v[100], j;
cin>>n;
for(i=0;i<n;i=i+1){
cin>>v[i];
}
for(i=0;i<n;i=i+1){
int r = sqrt(v[i]);
if (r * r == v[i]) {
n=n+1;
for(j=n-1;j>i;j=j-1){
v[j]=v[j-1];
}
v[i] = r;
i=i+1;
}
}

for (i = 0; i < n; i++) {


cout << v[i] << ' ';
}
int v[100],i,n,j,ind,min;
cin>>n;
for(i=0;i<n;i=i+1){
cin>>v[i];
}
min=v[0];
for(i=0;i<n;i=i+1){
if(min>v[i]){
min=v[i];
}
}
for(i=0;i<n;i=i+1){
if(v[i]==min){
ind = i;
for(j=ind;j<n;j=j+1){
v[j]=v[j+1];
}
n=n-1;
i=i-1;
}
}

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


cout << v[i] << ' ';
}

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