⚠️ Programy sú rozdelené z dôvodu prehľadnosti a pre rýchly prístup pre debug, preto nespĺňajú všetky stanovené podmienky od Cvičiaceho
⚠️ Program je rozčlenený do funkcií a blokov. Pre funkční program musíte spojiť všetky 3 bloky s mainom!
/* Musk Elon 1337 */
/* cvicenie 8 */
/* 11.11.2021 */
#include <stdio.h>
int NacitajMaticu(char *subor, int matica[10][10])
{
FILE *f = fopen(subor,"r");
int cllr = 0,succ=0;
if(f == NULL)
return 0;
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
succ += fscanf(f,"%d", &matica[i][j]);
if(feof(f))
{
cllr = 1;
break;
}
}
if(cllr==1)
break;
}
fclose(f);
if(succ!=100)
return 0;
else
return 1;
}
int AnalyzujMaticu(int m[10][10], int *zaporne, int *neparne)
{
int maxx = -100000,c_zap=0,c_nep=0;
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
if(m[i][j]<0)
c_zap++;
if(m[i][j] % 2 == 1)
c_nep++;
if(m[i][j]>maxx)
maxx = m[i][j];
}
}
*zaporne = c_zap;
*neparne = c_nep;
return maxx;
}
int VypisMaticu(int m[10][10])
{
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
printf("%5d ",m[i][j]);
}
printf("\n");
}
return 0;
}
int main()
{
int m[10][10], zaporne, neparne, max;
if (NacitajMaticu("vstup.txt", m))
{
max = AnalyzujMaticu(m, &zaporne, &neparne);
VypisMaticu(m);
printf("zaporne: %d, neparne: %d, maximum: %d", zaporne, neparne, max);
}
else
printf("citanie sa nepodarilo");
return 0;
}