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

Tema Info Vectori

The document contains 10 code snippets in C++. Each snippet includes code to read in an array of integers, perform some operation on the array such as finding the minimum/maximum values, printing the values, and returning 0 at the end of the main function. The snippets demonstrate various array processing techniques in C++.

Uploaded by

ericcristian695
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)
26 views6 pages

Tema Info Vectori

The document contains 10 code snippets in C++. Each snippet includes code to read in an array of integers, perform some operation on the array such as finding the minimum/maximum values, printing the values, and returning 0 at the end of the main function. The snippets demonstrate various array processing techniques in C++.

Uploaded by

ericcristian695
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

#633

#include <iostream>
using namespace std;
int v[1001],n,i,kp,ki;
int main()
{
cin>>n;
for(i=1;i<=n;i++)
{
cin>>v[i];
}
for(i=1;i<=n;i++)
{
if(v[i]%2==0)
kp++;
if(v[i]%2!=0)
ki++;

}
if(kp>ki)
cout<<kp-ki;
else
cout<<ki-kp;
return 0;
}

#546
#include <iostream>
using namespace std;
int v[1001], i, n;
int main()
{
cin >> n;
for(i=1; i<=n; i++)
cin >> v[i];
for(i=1; i<=n; i++)
if(v[i]%v[n]==0)
cout << v[i] << " ";
return 0;
}

#488
#include <iostream>
using namespace std;
int n, v[1001], i;
int main()
{
cin >> n;
for ( i = 1; i <= n; i++)
cin >> v[i];
for ( i = 2; i <= n; i = i + 2) cout << v[i] << " ";
cout << endl;
if (n % 2 == 0) n--;
for ( i = n; i > 0; i = i - 2) cout << v[i] << " ";
return 0;
}

#489
#include <iostream>
using namespace std;
int n, v[1000], i;
int main()
{
cin >> n;
for ( i = 1; i <= n; i++)
cin >> v[i];
for ( i = 2; i <= n; i = i + 2) cout << v[i] << " ";
cout << endl;
if (n % 2 == 0) n--;
for ( i = n; i > 0; i = i - 2) cout << v[i] << " ";
return 0;
}

#486
#include <iostream>
using namespace std;
int v[1001], n, maxim = -1, minim = 1000001;
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
cin >> v[i];
for (int i = 1; i <= n; i++)
{
if (v[i] > maxim)
maxim = v[i];
if (v[i] < minim)
minim = v[i];
}
cout << minim << " " << maxim;
return 0;
}
#553
#include <iostream>
using namespace std;
int n, v[1001], i, minim, maxim;
int main()
{
cin >> n;
for ( i = 1; i <= n; i++)
cin >> v[i];
minim = 1, maxim = 1;
for (int i = 2; i <= n; i++)
{
if (v[i] < v[minim]) minim = i;
if(v[i] > v[maxim]) maxim = i;
} cout << minim << " " << maxim;
return 0;
}

#547
#include <iostream>
using namespace std;
int n, maxim = -1, minim = 1000001, a, k = 0, v[1001];
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
cin >> v[i];
for (int i = 1; i <= n; i++)
{
if (v[i] < minim) minim = v[i];
else if (v[i] > maxim) maxim = v[i];
a = maxim - minim;
}
a = maxim - minim;
for (int i = 1; i <= n; i++)
if (a == v[i]) k++;
cout << k;
}

#490
#include <iostream>
using namespace std;
int v[1001], n, poz_min, poz_max, minim = 100001, maxim = -1, k;
int main()
{
cin >> n;
for (int i = 0; i < n; ++i)
cin >> v[i];
for (int i = 0; i < n; ++i)
{
if (v[i] > maxim)
{
maxim = v[i];
poz_max = i;
}
else if (v[i] < minim)
{
minim = v[i];
poz_min = i;
}
}
if (poz_min > poz_max)
{
k = poz_min;
poz_min = poz_max;
poz_max = k;
}
for (int i = poz_min; i <= poz_max; ++i)
{
cout << v[i] << " ";
} return 0;
}

You might also like