Professional Documents
Culture Documents
Лабораторна робота №5
Лабораторна робота №5
ЗВІТ
Про виконання лабораторної роботи № 5
“Програмування роботи з масивами мовою С.”
з дисципліни “АЛГОРИТМІЗАЦІЯ І ПРОГРАМУВАННЯ”
Варіант №16
2020
Лабораторна робота №5
Тема: Програмування роботи з масивами мовою С.
Мета: Реалізація алгоритмів з одновимірними і двовимірними масивами
мовою C.
Завдання: Здобути навички створення, відлагодження та реалізації програм
для обробки даних з одновимірних і двовимірних масивів мовою C.
GitHub: https://github.com/Aves2001/GitHub_Lab_5_Lebid_Eduard
#include <stdio.h>
#include <conio.h>
#include <windows.h>
int s = 0;
int size = 0;
int zz = 0;
// UTF-8
SetConsoleCP(65001);
SetConsoleOutputCP(65001);
//
int a[size];
do
{
if (a[i]>0)
bil0++;
i++;
}
while (i<size);
system("cls");
printf("*************************************\r\n");
printf("* Кількість додатних елементів = %d *\r\n", bil0);
do
{
if (a[j]<0)
men0++;
j++;
}
while (j<size);
printf("* Кількість від'ємних елементів = %d *\r\n", men0);
printf("*************************************\r\n");
if (men0<=bil0)
{
printf("\r\n%c1%c\r\n", '"', '"');
}else printf("\r\n%c0%c\r\n", '"', '"');
if (zz == 1)
{
printf("\r\nПорядкові номери нулів:");
for (int i = 0; i < size; i++)
{
if (i+1 == size || i+1 == size && a[i]==0)
{
printf(" %d.", i+1);
} else if (a[i] == 0) printf(" %d,", i+1);
}
}
// Вертаєм chcp
SetConsoleCP(chcp);
SetConsoleOutputCP(chcpOut);
//
getch();
return 0;
}
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <windows.h>
int s = 0;
int size = 0;
int num = 0;
int d=1;
// UTF-8
SetConsoleCP(65001);
SetConsoleOutputCP(65001);
//
int a[size];
int bil0=0;
int i =0;
do
{
if (a[i]>0)
bil0++;
i++;
}
while (i<size);
system("cls");
printf("\r\n1) Кількість додатних елементів масиву = %d\r\n", bil0);
// Вертаєм chcp
SetConsoleCP(chcp);
SetConsoleOutputCP(chcpOut);
//
getch();
return 0;
}
B)
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <windows.h>
#include <time.h>
const int Low=-100, High=100;
int size = 0;
int num = 0;
int d = 1;
// UTF-8
SetConsoleCP(65001);
SetConsoleOutputCP(65001);
//
int a[size];
int i =0;
srand(time(0));
for (int i=0; i<size; i++)
a[i]=Low + rand() % (High - Low + 1);
int bil0=0;
do
{
if (a[i]>0)
bil0++;
i++;
}
while (i<size);
system("cls");
printf("\r\n1) Кількість додатних елементів масиву = %d\r\n", bil0);
for (i=1; i < size; i++)
{
if (abs(a[i]) <= abs(a[num]))
num = i;
}
// Вертаєм chcp
SetConsoleCP(chcp);
SetConsoleOutputCP(chcpOut);
//
getch();
return 0;
}
( )
3 2 4 9
Вхідні дані: n = 3; m = 4; A= 7 3 10 3
5 4 6 1
int i = 0;
int j = 0;
int num = 0;
int n = 0;
int m = 0;
// UTF-8
SetConsoleCP(65001);
SetConsoleOutputCP(65001);
//
printf("\r\nВведіть: ");
printf("\r\nКількість рядків: ");
scanf("%d", &n);
printf("Кількість стовпців: ");
scanf("%d", &m);
printf("\r\n");
int n = 3;
int m = 4;
int a[n][m];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
printf("A[%d][%d]=", i, j);
scanf("%d", &a[i][j]); }
int d[m];
int i,j=0;
for(j=0;j<m;j++)
{
d[j]=1; for(i=0;i<n;i++)
if(a[i][j]!=0)
d[j]*=a[i][j];
}
///////////////
int i = 0;
int j = 0;
int num = 0;
int n = 0;
int m = 0;
int temp = 0;
// UTF-8
SetConsoleCP(65001);
SetConsoleOutputCP(65001);
//
printf("\r\nВведіть: ");
printf("\r\nКількість рядків: ");
scanf ("%d", &n);
printf("Кількість стовпців: ");
scanf ("%d", &m);
int a[n][m];
printf("\r\n\nДо сортування:\r\n");
////////////
for (int q=0; q<n; q++)
{
for (int j = 0; j < m; j++)
{
for (int i = 1; i < n; i++)
{
if (a[i-1][j] < a[i][j])
{
temp = a[i-1][j];
a[i-1][j] = a[i][j];
a[i][j] = temp;
}
}
}
}
////////////
printf("\r\n\nПісля сортування:\r\n");
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
printf("a[%d][%d]=%d\t", i, j, a[i][j]); printf("\n");
}
// Вертаєм chcp
SetConsoleCP(chcp);
SetConsoleOutputCP(chcpOut);
//
getch();
return 0;
}
GitHub: https://github.com/Aves2001/GitHub_Lab_5_Lebid_Eduard