|
Minimal element massivda aniqlanishi kerak. Dastlabki ma'lumotlar: 3, -7,8,10, -75,128,7,10
|
tarix | 23.11.2022 | ölçüsü | 34,78 Kb. | | #119768 |
| 6 (2)
6
|
Minimal element massivda aniqlanishi kerak.
Dastlabki ma'lumotlar: 3, -7,8,10, -75,128,7,10.
|
#include
using namespace std;
int main()
{
int a[] = {3, -7, 8, 10, -75, 128, 7, 10};
int k = 0;
int b[k];
cout << "a[]=";
for (int i = 0; i <= 7; i++)
{
cout << a[i] << " ";
}
for (int i = 0; i <= 7; i++)
{
if (a[i] < 0)
{
b[k++] = a[i];
}
}
cout << endl;
cout << "b[]=";
for (int i = 0; i < k; i++)
{
cout << b[i] << " ";
}
}
Daraxt tartiblash usuli yordamida dinamik massiv elementlarini o'sish va kamayish tartibida tartiblang.
6 A мaтрицaнинг тoқ сaтр элементлaрининг йиғиндисини ҳисобланг
#include
using namespace std;
int main()
{
int n;
cout << "n = ";
cin >> n;
int a[n][n];
int s = 0;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
a[i][j] = rand() % 101;
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
cout << a[i][j] << "\t";
}
cout << endl;
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (i % 2 != 0)
{
s += a[i][j];
}
}
}
cout << "S=" << s << endl;
}
Dostları ilə paylaş: |
|
|