int main() { int A[15] = {1,2,3,-1,-2,-3,1,2,-1,-2,1,2,3,4,5}; int k = 0; for (int i=0; i<15; i++) k+=(A[i]<0) ? 1:0; std::cout <<(k/15*100) <<'\n'; return 0; }
2) #include <iostream>
int main() { int A[20] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,33,20}; for (int i=0; i<20; i++) if (A[i]%10==3) std::cout <<A[i] <<std::endl; return 0; }
3) #include <iostream>
int main() { int A[13] = {1,2,3,4,5,6,7,8,9,10,11,12,13}; usnigned int p = 1; for (int i=0; i<13; i++) p*=(A[i]>9 && A[i]<100) ? A[i]:1; std::cout <<p <<'\n'; return 0; }
4) #include <iostream>
int main() { int A[30] = {1,2,3,4,5,6,7,8,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22, 23 24 25 26,27,28,29,28}; bool flag = true; for (int i=0; i<29; i++) if (a[i]>a[i+1]) { flag = false; break; } std::cout <<std::boolalpha <<flag <<std::endl; return 0; }
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
const int size = 10;
int main()
{
srand (time(0));
int a[size];
int k1 = 0,k2 = 0;
for (int i=0; i<size; i++)
{
a[i]=rand()%20-10;
cout <<a[i] <' ';
k1+=(a[i]>0 && a[i]%2) ? a[i]:0;
k2+=(a[i]<0 && !(a[i]%2)) ? 1:0;
}
cout <<k1 <<end <<k2 <<endl;
return 0;
}
2)
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
const int size = 10;
int main()
{
srand (time(0));
int a[size];
int k1 = 0,k2 = 0;
for (int i=0; i<size; i++)
{
a[i]=rand()%20-10;
cout <<a[i] <' ';
k1+=(a[i]<0 && !(i%2)) ? 1:0;
k2+=(a[i]>0 && !(a[i]%2) && i%2) ? a[i]:0;
}
cout <<k2 <<end <<k2 <<endl;
return 0;
}
#include <iostream>
int main()
{
int A[15] = {1,2,3,-1,-2,-3,1,2,-1,-2,1,2,3,4,5};
int k = 0;
for (int i=0; i<15; i++)
k+=(A[i]<0) ? 1:0;
std::cout <<(k/15*100) <<'\n';
return 0;
}
2)
#include <iostream>
int main()
{
int A[20] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,33,20};
for (int i=0; i<20; i++)
if (A[i]%10==3)
std::cout <<A[i] <<std::endl;
return 0;
}
3)
#include <iostream>
int main()
{
int A[13] = {1,2,3,4,5,6,7,8,9,10,11,12,13};
usnigned int p = 1;
for (int i=0; i<13; i++)
p*=(A[i]>9 && A[i]<100) ? A[i]:1;
std::cout <<p <<'\n';
return 0;
}
4)
#include <iostream>
int main()
{
int A[30] = {1,2,3,4,5,6,7,8,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,
23 24 25 26,27,28,29,28};
bool flag = true;
for (int i=0; i<29; i++)
if (a[i]>a[i+1])
{
flag = false;
break;
}
std::cout <<std::boolalpha <<flag <<std::endl;
return 0;
}