| 1 | najgolem od minimumite po redica
|
|---|
| 2 | #include <stdio.h>
|
|---|
| 3 | #include <stdlib.h>
|
|---|
| 4 |
|
|---|
| 5 | int main()
|
|---|
| 6 | {
|
|---|
| 7 | int m,n,i,j,red=0,max=-9999,min=9999;
|
|---|
| 8 | scanf("%d%d",&m,&n);
|
|---|
| 9 | int mat[m][n];
|
|---|
| 10 |
|
|---|
| 11 | for(i=0;i<m;i++)
|
|---|
| 12 | {
|
|---|
| 13 | for(j=0;j<n;j++)
|
|---|
| 14 | {
|
|---|
| 15 | scanf("%d",&mat[i][j]);
|
|---|
| 16 | }
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 | for(i=0;i<m;i++)
|
|---|
| 20 | {
|
|---|
| 21 | max=-9999;
|
|---|
| 22 |
|
|---|
| 23 | for(j=0;j<n;j++)
|
|---|
| 24 | {
|
|---|
| 25 |
|
|---|
| 26 | if(min>mat[i][j])
|
|---|
| 27 | {
|
|---|
| 28 | min=mat[i][j];
|
|---|
| 29 | }
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | if(max<min)
|
|---|
| 33 | {
|
|---|
| 34 | max=min;
|
|---|
| 35 | red=i;
|
|---|
| 36 | }
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | for(j=0;j<n-1;j++)
|
|---|
| 40 | {
|
|---|
| 41 | printf("%d ",mat[red][j]);
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | printf("%d",mat[red][j]);
|
|---|
| 45 |
|
|---|
| 46 | return 0;
|
|---|
| 47 | }
|
|---|
| 48 | najgolem pogoden broj
|
|---|
| 49 | #include <stdio.h>
|
|---|
| 50 | #include <stdlib.h>
|
|---|
| 51 |
|
|---|
| 52 | int main()
|
|---|
| 53 | {
|
|---|
| 54 | int m,n,i,j,a,max=0;
|
|---|
| 55 | scanf ("%d%d",&m,&n);
|
|---|
| 56 | int mat[m][n];
|
|---|
| 57 | for(i=1;i<=m;i++)
|
|---|
| 58 | {
|
|---|
| 59 | for(j=1;j<=n;j++)
|
|---|
| 60 | {
|
|---|
| 61 | scanf("%d",&mat[i][j]);
|
|---|
| 62 | }
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | for(i=1;i<=m;i++)
|
|---|
| 66 | {
|
|---|
| 67 | for(j=1;j<=n;j++)
|
|---|
| 68 | {
|
|---|
| 69 | a=mat[i][j];
|
|---|
| 70 | if(a%i==0&&a%j==0)
|
|---|
| 71 | {
|
|---|
| 72 | if(max<a)
|
|---|
| 73 | {
|
|---|
| 74 | max=a;
|
|---|
| 75 | }
|
|---|
| 76 | }
|
|---|
| 77 | }
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | if(max>0)
|
|---|
| 81 | {
|
|---|
| 82 | printf ("%d\n",max);
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | else
|
|---|
| 86 | {
|
|---|
| 87 | printf ("Nema pogoden broj\n");
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 | return 0;
|
|---|
| 92 | }
|
|---|
| 93 | najmal od maksimalni elementi po kolona
|
|---|
| 94 | #include <stdio.h>
|
|---|
| 95 | #include <stdlib.h>
|
|---|
| 96 |
|
|---|
| 97 | int main()
|
|---|
| 98 | {
|
|---|
| 99 | int mat[9][9],m,n,i,j,maks=-9999,min=9999,kol=0,pom;
|
|---|
| 100 | scanf("%d%d",&m,&n);
|
|---|
| 101 |
|
|---|
| 102 | for(i=0;i<m;i++)
|
|---|
| 103 | {
|
|---|
| 104 | for(j=0;j<n;j++)
|
|---|
| 105 | {
|
|---|
| 106 | scanf("%d",&mat[i][j]);
|
|---|
| 107 | }
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | for(j=0;j<n;j++)
|
|---|
| 111 | {
|
|---|
| 112 | maks=-9999;
|
|---|
| 113 | for(i=0;i<m;i++)
|
|---|
| 114 | {
|
|---|
| 115 |
|
|---|
| 116 | if(maks<mat[i][j])
|
|---|
| 117 | {
|
|---|
| 118 | maks=mat[i][j];
|
|---|
| 119 |
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | if(min>maks)
|
|---|
| 126 | {
|
|---|
| 127 | min=maks;
|
|---|
| 128 | kol=j;
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | for(i=0; i<m-1;i++)
|
|---|
| 137 | {
|
|---|
| 138 | printf("%d ",mat[i][kol]);
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | printf("%d",mat[i][kol]);
|
|---|
| 142 |
|
|---|
| 143 | return 0;
|
|---|
| 144 | }
|
|---|
| 145 | pechatenje na element koj se pojavuva vo sekoja kolona
|
|---|
| 146 | #include <stdio.h>
|
|---|
| 147 | #include <stdlib.h>
|
|---|
| 148 |
|
|---|
| 149 | int main()
|
|---|
| 150 | {
|
|---|
| 151 | int m,n,i,j,zname,k,l,a,b;
|
|---|
| 152 | scanf("%d%d",&m,&n);
|
|---|
| 153 | int mat[m][n];
|
|---|
| 154 |
|
|---|
| 155 | for(i=0;i<m;i++)
|
|---|
| 156 | {
|
|---|
| 157 | for(j=0;j<n;j++)
|
|---|
| 158 | {
|
|---|
| 159 | scanf("%d",&mat[i][j]);
|
|---|
| 160 | }
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | for(i=0;i<m;i++)
|
|---|
| 164 | {
|
|---|
| 165 | a=mat[i][0];
|
|---|
| 166 | zname=0;
|
|---|
| 167 |
|
|---|
| 168 | for(k=1;k<n;k++)
|
|---|
| 169 | {
|
|---|
| 170 | for(l=0;l<m;l++)
|
|---|
| 171 | {
|
|---|
| 172 | b=mat[l][k];
|
|---|
| 173 |
|
|---|
| 174 | if(a==b)
|
|---|
| 175 | {
|
|---|
| 176 | zname=1;
|
|---|
| 177 | }
|
|---|
| 178 | }
|
|---|
| 179 | if(zname!=1)
|
|---|
| 180 | {
|
|---|
| 181 | break;
|
|---|
| 182 | }
|
|---|
| 183 | }
|
|---|
| 184 |
|
|---|
| 185 | if(zname==1)
|
|---|
| 186 | {
|
|---|
| 187 | printf("Elementot %d go zadovoluva uslovot\n",a);
|
|---|
| 188 | }
|
|---|
| 189 |
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | return 0;
|
|---|
| 193 | }
|
|---|
| 194 | za redici
|
|---|
| 195 | #include <stdio.h>
|
|---|
| 196 | #include <stdlib.h>
|
|---|
| 197 |
|
|---|
| 198 | int main()
|
|---|
| 199 | {
|
|---|
| 200 | int m,n,i,j,a,zname,k,b;
|
|---|
| 201 | scanf("%d%d",&m,&n);
|
|---|
| 202 | int mat[m][n];
|
|---|
| 203 |
|
|---|
| 204 | for(i=0;i<m;i++)
|
|---|
| 205 | {
|
|---|
| 206 | for(j=0;j<n;j++)
|
|---|
| 207 | {
|
|---|
| 208 | scanf("%d",&mat[i][j]);
|
|---|
| 209 | }
|
|---|
| 210 | }
|
|---|
| 211 |
|
|---|
| 212 | for(j=0;j<n;j++)
|
|---|
| 213 | {
|
|---|
| 214 | a = mat[0][j];
|
|---|
| 215 | zname=0;
|
|---|
| 216 | for(i=1;i<m;i++)
|
|---|
| 217 | {
|
|---|
| 218 | zname=0;
|
|---|
| 219 |
|
|---|
| 220 | for(k=0;k<n;k++)
|
|---|
| 221 | {
|
|---|
| 222 | b = mat[i][k];
|
|---|
| 223 |
|
|---|
| 224 | if(a==b)
|
|---|
| 225 | {
|
|---|
| 226 | zname=1;
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| 231 | if(zname!=1)
|
|---|
| 232 | {
|
|---|
| 233 | break;
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 | }
|
|---|
| 238 |
|
|---|
| 239 | if(zname==1)
|
|---|
| 240 | {
|
|---|
| 241 | printf("Elementot %d go zadovuluva uslovot\n",mat[0][j]);
|
|---|
| 242 | }
|
|---|
| 243 |
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 |
|
|---|
| 247 | return 0;
|
|---|
| 248 | }
|
|---|
| 249 | proizvod na sosedni elementii
|
|---|
| 250 | #include <stdio.h>
|
|---|
| 251 | #include <stdlib.h>
|
|---|
| 252 |
|
|---|
| 253 | int main()
|
|---|
| 254 | {
|
|---|
| 255 | int m,n,i,j,a,proizvod=1;
|
|---|
| 256 | scanf ("%d%d",&m,&n);
|
|---|
| 257 | int mat[m][n];
|
|---|
| 258 | int mat2[m][n];
|
|---|
| 259 |
|
|---|
| 260 | for(i=0;i<m;i++)
|
|---|
| 261 | {
|
|---|
| 262 | for(j=0;j<n;j++)
|
|---|
| 263 | {
|
|---|
| 264 | scanf ("%d",&mat[i][j]);
|
|---|
| 265 | mat2[i][j]=mat[i][j];
|
|---|
| 266 | }
|
|---|
| 267 | }
|
|---|
| 268 |
|
|---|
| 269 | for(i=0;i<m;i++)
|
|---|
| 270 | {
|
|---|
| 271 | for(j=0;j<n;j++)
|
|---|
| 272 | {
|
|---|
| 273 | a=mat[i][j];
|
|---|
| 274 | proizvod=1;
|
|---|
| 275 |
|
|---|
| 276 | if(i>0 && j<n-1 && (a>mat[i-1][j+1])) // gore desno
|
|---|
| 277 | {
|
|---|
| 278 | proizvod*=mat[i-1][j+1];
|
|---|
| 279 | }
|
|---|
| 280 |
|
|---|
| 281 | if(i>0 && j>0 && (a > mat[i-1][j-1])) // gore levo
|
|---|
| 282 | {
|
|---|
| 283 | proizvod*=mat[i-1][j-1];
|
|---|
| 284 | }
|
|---|
| 285 |
|
|---|
| 286 | if( j<n-1 && i<m-1 && (a > mat[i+1][j+1])) // dole desno
|
|---|
| 287 | {
|
|---|
| 288 | proizvod*=mat[i+1][j+1];
|
|---|
| 289 | }
|
|---|
| 290 |
|
|---|
| 291 | if(j>0 && i<m-1 && (a > mat[i+1][j-1])) // dole levo
|
|---|
| 292 | {
|
|---|
| 293 | proizvod*=mat[i+1][j-1];
|
|---|
| 294 | }
|
|---|
| 295 |
|
|---|
| 296 | mat2[i][j]=proizvod;
|
|---|
| 297 | }
|
|---|
| 298 | }
|
|---|
| 299 |
|
|---|
| 300 | for(i=0;i<m;i++)
|
|---|
| 301 | {
|
|---|
| 302 | for(j=0;j<n;j++)
|
|---|
| 303 | {
|
|---|
| 304 | printf ("%d ", mat2[i][j]);
|
|---|
| 305 | }
|
|---|
| 306 | printf ("\n");
|
|---|
| 307 | }
|
|---|
| 308 |
|
|---|
| 309 |
|
|---|
| 310 | return 0;
|
|---|
| 311 | }
|
|---|
| 312 | rastechka i opagjachka matrica
|
|---|
| 313 | #include <stdio.h>
|
|---|
| 314 | #include <stdlib.h>
|
|---|
| 315 |
|
|---|
| 316 | int main()
|
|---|
| 317 | {
|
|---|
| 318 | int m,n,i,j,k,t;
|
|---|
| 319 | scanf("%d%d",&m,&n);
|
|---|
| 320 | int mat[m][n];
|
|---|
| 321 |
|
|---|
| 322 |
|
|---|
| 323 | for(i=0;i<m;i++)
|
|---|
| 324 | {
|
|---|
| 325 | for(j=0;j<n;j++)
|
|---|
| 326 | {
|
|---|
| 327 | scanf("%d",&mat[i][j]);
|
|---|
| 328 | }
|
|---|
| 329 | }
|
|---|
| 330 |
|
|---|
| 331 | for(i=0;i<m;i++)
|
|---|
| 332 | {
|
|---|
| 333 | for(j=0;j<n;j++)
|
|---|
| 334 | {
|
|---|
| 335 | for(t=0;t<m;t++)
|
|---|
| 336 | {
|
|---|
| 337 | for(k=0;k<n;k++)
|
|---|
| 338 | {
|
|---|
| 339 | if(mat[i][j]>mat[t][k])
|
|---|
| 340 | {
|
|---|
| 341 | int temp=mat[i][j];
|
|---|
| 342 | mat[i][j]=mat[t][k];
|
|---|
| 343 | mat[t][k]=temp;
|
|---|
| 344 | }
|
|---|
| 345 | }
|
|---|
| 346 | }
|
|---|
| 347 | }
|
|---|
| 348 | }
|
|---|
| 349 |
|
|---|
| 350 | printf("Opagjachka matrica: \n");
|
|---|
| 351 | for(i=0;i<m;i++)
|
|---|
| 352 | {
|
|---|
| 353 | for(j=0;j<n;j++)
|
|---|
| 354 | {
|
|---|
| 355 | printf("%d ",mat[i][j]);
|
|---|
| 356 | }
|
|---|
| 357 | printf("\n");
|
|---|
| 358 | }
|
|---|
| 359 |
|
|---|
| 360 | printf("\n");
|
|---|
| 361 |
|
|---|
| 362 | for(i=0;i<m;i++)
|
|---|
| 363 | {
|
|---|
| 364 | for(j=0;j<n;j++)
|
|---|
| 365 | {
|
|---|
| 366 | for(t=0;t<m;t++)
|
|---|
| 367 | {
|
|---|
| 368 | for(k=0;k<n;k++)
|
|---|
| 369 | {
|
|---|
| 370 | if(mat[i][j]<mat[t][k])
|
|---|
| 371 | {
|
|---|
| 372 | int temp=mat[i][j];
|
|---|
| 373 | mat[i][j]=mat[t][k];
|
|---|
| 374 | mat[t][k]=temp;
|
|---|
| 375 | }
|
|---|
| 376 | }
|
|---|
| 377 | }
|
|---|
| 378 | }
|
|---|
| 379 | }
|
|---|
| 380 |
|
|---|
| 381 | printf("Rastechka matrica: \n");
|
|---|
| 382 |
|
|---|
| 383 | for(i=0;i<m;i++)
|
|---|
| 384 | {
|
|---|
| 385 | for(j=0;j<n;j++)
|
|---|
| 386 | {
|
|---|
| 387 | printf("%d ",mat[i][j]);
|
|---|
| 388 | }
|
|---|
| 389 | printf("\n");
|
|---|
| 390 | }
|
|---|
| 391 |
|
|---|
| 392 | return 0;
|
|---|
| 393 | }
|
|---|
| 394 | matrica sovrseni
|
|---|
| 395 | #include <stdio.h>
|
|---|
| 396 | int sovrsenbroj(int n) {
|
|---|
| 397 | int suma=0,i;
|
|---|
| 398 | for(i=1; i<n; i++) {
|
|---|
| 399 | if(n%i==0) {
|
|---|
| 400 | suma+=i;
|
|---|
| 401 | }
|
|---|
| 402 | }
|
|---|
| 403 | if(n==suma)
|
|---|
| 404 | return 1;
|
|---|
| 405 | else
|
|---|
| 406 | return 0;
|
|---|
| 407 |
|
|---|
| 408 | }
|
|---|
| 409 |
|
|---|
| 410 | int main () {
|
|---|
| 411 | int n,i,j,max=0,min=0,flag=0,zero=0;
|
|---|
| 412 | scanf("%d",&n);
|
|---|
| 413 | int a[n][n],b[n][n],c[n][n];
|
|---|
| 414 | for(i=0; i<n; i++)
|
|---|
| 415 | for(j=0; j<n; j++) {
|
|---|
| 416 | scanf("%d",&a[i][j]);
|
|---|
| 417 | c[i][j]=0;
|
|---|
| 418 |
|
|---|
| 419 | }
|
|---|
| 420 |
|
|---|
| 421 | for(i=0; i<n; i++)
|
|---|
| 422 | for(j=0; j<n; j++) {
|
|---|
| 423 | if(sovrsenbroj(a[i][j])==1) {
|
|---|
| 424 | if(flag==0)
|
|---|
| 425 | min=a[i][j];
|
|---|
| 426 |
|
|---|
| 427 | flag=1;
|
|---|
| 428 | if(min>a[i][j])
|
|---|
| 429 | min=a[i][j];
|
|---|
| 430 | if(max<a[i][j])
|
|---|
| 431 | max=a[i][j];
|
|---|
| 432 | }
|
|---|
| 433 | }
|
|---|
| 434 |
|
|---|
| 435 | for(i=0; i<n; i++)
|
|---|
| 436 | for(j=0; j<n; j++) {
|
|---|
| 437 | if(i==j || i+j==n-1)
|
|---|
| 438 | b[i][j]=max;
|
|---|
| 439 | else
|
|---|
| 440 | b[i][j]=min;
|
|---|
| 441 | }
|
|---|
| 442 | if(flag==1) {
|
|---|
| 443 | for(i=0; i<n; i++) {
|
|---|
| 444 | printf("\n");
|
|---|
| 445 | for(j=0; j<n; j++) {
|
|---|
| 446 | printf("%d ",b[i][j]);
|
|---|
| 447 |
|
|---|
| 448 | }
|
|---|
| 449 |
|
|---|
| 450 | }
|
|---|
| 451 | printf("\n%d",max-min);
|
|---|
| 452 | } else {
|
|---|
| 453 | for(i=0; i<n; i++) {
|
|---|
| 454 | printf("\n");
|
|---|
| 455 | for(j=0; j<n; j++) {
|
|---|
| 456 | printf("%d ",c[i][j]);
|
|---|
| 457 |
|
|---|
| 458 | }
|
|---|
| 459 |
|
|---|
| 460 |
|
|---|
| 461 |
|
|---|
| 462 | }
|
|---|
| 463 | printf("\n%d",zero);
|
|---|
| 464 |
|
|---|
| 465 | }
|
|---|
| 466 |
|
|---|
| 467 | return 0;
|
|---|
| 468 |
|
|---|
| 469 | }
|
|---|
| 470 | zbir na dijagonali
|
|---|
| 471 | #include <stdio.h>
|
|---|
| 472 | #include <stdlib.h>
|
|---|
| 473 |
|
|---|
| 474 | int main()
|
|---|
| 475 | {
|
|---|
| 476 | int n,i,j,k,suma=0,sumamax=-9999;
|
|---|
| 477 | scanf("%d",&n);
|
|---|
| 478 | int mat[n][n];
|
|---|
| 479 |
|
|---|
| 480 | for(i=0;i<n;i++)
|
|---|
| 481 | {
|
|---|
| 482 | for(j=0;j<n;j++)
|
|---|
| 483 | {
|
|---|
| 484 | scanf("%d",&mat[i][j]);
|
|---|
| 485 | }
|
|---|
| 486 | }
|
|---|
| 487 |
|
|---|
| 488 | for(k=n;k>0;k--)
|
|---|
| 489 | {
|
|---|
| 490 | suma=0;
|
|---|
| 491 |
|
|---|
| 492 | for(i=0;i<k;i++)
|
|---|
| 493 | {
|
|---|
| 494 | suma+=mat[(n-k) - (n-k) + i][k-i-1];
|
|---|
| 495 | }
|
|---|
| 496 |
|
|---|
| 497 | if(sumamax<suma)
|
|---|
| 498 | {
|
|---|
| 499 | sumamax=suma;
|
|---|
| 500 | }
|
|---|
| 501 | }
|
|---|
| 502 |
|
|---|
| 503 | printf("%d",sumamax);
|
|---|
| 504 |
|
|---|
| 505 | return 0;
|
|---|
| 506 | }
|
|---|
| 507 | zamena na sekoj ele. so suma na negovite dijag. sosedi
|
|---|
| 508 | #include <stdio.h>
|
|---|
| 509 | #include <stdlib.h>
|
|---|
| 510 |
|
|---|
| 511 | int main()
|
|---|
| 512 | {
|
|---|
| 513 | int mat[10][10],m,n,i,j,mat2[10][10],a;
|
|---|
| 514 |
|
|---|
| 515 | scanf("%d%d",&m,&n);
|
|---|
| 516 |
|
|---|
| 517 | for(i=0;i<m;i++)
|
|---|
| 518 | {
|
|---|
| 519 | for(j=0;j<n;j++)
|
|---|
| 520 | {
|
|---|
| 521 | scanf("%d",&mat[i][j]);
|
|---|
| 522 | }
|
|---|
| 523 | }
|
|---|
| 524 |
|
|---|
| 525 | for(i=0;i<m;i++)
|
|---|
| 526 | {
|
|---|
| 527 |
|
|---|
| 528 | for(j=0;j<n;j++)
|
|---|
| 529 | {
|
|---|
| 530 | a=mat[i][j];
|
|---|
| 531 | int suma=0;
|
|---|
| 532 |
|
|---|
| 533 | if(i>0&&j>0)
|
|---|
| 534 | {
|
|---|
| 535 | suma+=mat[i-1][j-1];// IMAM
|
|---|
| 536 | }
|
|---|
| 537 |
|
|---|
| 538 | if(i<m-1 && j>0)
|
|---|
| 539 | {
|
|---|
| 540 | suma+=mat[i+1][j-1];// IMAM
|
|---|
| 541 | }
|
|---|
| 542 |
|
|---|
| 543 | if(i<m-1 && j<n-1)
|
|---|
| 544 | {
|
|---|
| 545 | suma+=mat[i+1][j+1]; //IMAM
|
|---|
| 546 | }
|
|---|
| 547 |
|
|---|
| 548 | if(i>0 && j<n-1)
|
|---|
| 549 | {
|
|---|
| 550 | suma+=mat[i-1][j+1];
|
|---|
| 551 | }
|
|---|
| 552 |
|
|---|
| 553 | mat2[i][j]=suma;
|
|---|
| 554 |
|
|---|
| 555 | }
|
|---|
| 556 | }
|
|---|
| 557 |
|
|---|
| 558 | for(i=0;i<m;i++)
|
|---|
| 559 | {
|
|---|
| 560 | for(j=0;j<n;j++)
|
|---|
| 561 | {
|
|---|
| 562 | printf("%d ",mat2[i][j]);
|
|---|
| 563 | }
|
|---|
| 564 |
|
|---|
| 565 | printf("\n");
|
|---|
| 566 | }
|
|---|
| 567 |
|
|---|
| 568 | return 0;
|
|---|
| 569 | }
|
|---|
| 570 | transformacija 1-n red
|
|---|
| 571 | #include <stdio.h>
|
|---|
| 572 | #include <stdlib.h>
|
|---|
| 573 |
|
|---|
| 574 | int main()
|
|---|
| 575 | {
|
|---|
| 576 | int m,n,i,j,suma1=0,suma2=0,k;
|
|---|
| 577 | scanf("%d%d",&m,&n);
|
|---|
| 578 | int mat[m][n];
|
|---|
| 579 |
|
|---|
| 580 | for(i=0;i<m;i++)
|
|---|
| 581 | {
|
|---|
| 582 | for(j=0;j<n;j++)
|
|---|
| 583 | {
|
|---|
| 584 | scanf("%d",&mat[i][j]);
|
|---|
| 585 | }
|
|---|
| 586 | }
|
|---|
| 587 |
|
|---|
| 588 |
|
|---|
| 589 |
|
|---|
| 590 | for(i=0;i<m/2;i++)
|
|---|
| 591 | {
|
|---|
| 592 | for(j=0;j<n;j++)
|
|---|
| 593 | {
|
|---|
| 594 | suma1+=mat[i][j];
|
|---|
| 595 | suma2+=mat[m-i-1][j];
|
|---|
| 596 | }
|
|---|
| 597 |
|
|---|
| 598 | if(suma1>suma2)
|
|---|
| 599 | {
|
|---|
| 600 | for(k=0;k<n;k++)
|
|---|
| 601 | {
|
|---|
| 602 | int temp=mat[i][k];
|
|---|
| 603 | mat[i][k]=mat[m-i-1][k];
|
|---|
| 604 | mat[m-i-1][k]=temp;
|
|---|
| 605 | }
|
|---|
| 606 | }
|
|---|
| 607 | }
|
|---|
| 608 |
|
|---|
| 609 | for(i=0;i<m;i++)
|
|---|
| 610 | {
|
|---|
| 611 | for(j=0;j<n;j++)
|
|---|
| 612 | {
|
|---|
| 613 | printf("%d ",mat[i][j]);
|
|---|
| 614 | }
|
|---|
| 615 | printf("\n");
|
|---|
| 616 | }
|
|---|
| 617 |
|
|---|
| 618 | return 0;
|
|---|
| 619 | }
|
|---|
| 620 | transformacija 1-n kol
|
|---|
| 621 | #include <stdio.h>
|
|---|
| 622 | #include <stdlib.h>
|
|---|
| 623 |
|
|---|
| 624 | int main()
|
|---|
| 625 | {
|
|---|
| 626 | int mat[100][100],m,n,i,j,k,proizvod=1,proizvod_dva=1;
|
|---|
| 627 |
|
|---|
| 628 | scanf("%d%d",&m,&n);
|
|---|
| 629 |
|
|---|
| 630 | for(i=0;i<m;i++)
|
|---|
| 631 | {
|
|---|
| 632 | for(j=0;j<n;j++)
|
|---|
| 633 | {
|
|---|
| 634 | scanf("%d",&mat[i][j]);
|
|---|
| 635 | }
|
|---|
| 636 | }
|
|---|
| 637 |
|
|---|
| 638 | for(j=0;j<n/2;j++)
|
|---|
| 639 | {
|
|---|
| 640 | for(i=0;i<m;i++)
|
|---|
| 641 | {
|
|---|
| 642 | proizvod*=mat[i][j];
|
|---|
| 643 | proizvod_dva*=mat[i][n-j-1];
|
|---|
| 644 | }
|
|---|
| 645 |
|
|---|
| 646 | if(proizvod>proizvod_dva)
|
|---|
| 647 | {
|
|---|
| 648 | for(k=0;k<n;k++)
|
|---|
| 649 | {
|
|---|
| 650 | int temp=mat[k][j];
|
|---|
| 651 | mat[k][j]=mat[k][n-j-1];
|
|---|
| 652 | mat[k][n-j-1]=temp;
|
|---|
| 653 | }
|
|---|
| 654 | }
|
|---|
| 655 | }
|
|---|
| 656 |
|
|---|
| 657 | for(i=0;i<m;i++)
|
|---|
| 658 | {
|
|---|
| 659 | for(j=0;j<n;j++)
|
|---|
| 660 | {
|
|---|
| 661 | printf("%d ",mat[i][j]);
|
|---|
| 662 | }
|
|---|
| 663 | printf("\n");
|
|---|
| 664 | }
|
|---|
| 665 | return 0;
|
|---|
| 666 | }
|
|---|
| 667 | beli polinja
|
|---|
| 668 | #include <stdio.h>
|
|---|
| 669 | #include <stdlib.h>
|
|---|
| 670 |
|
|---|
| 671 | int main()
|
|---|
| 672 | {
|
|---|
| 673 | int n,i,j,suma=0,k,a;
|
|---|
| 674 | scanf("%d",&n);
|
|---|
| 675 | int mat[n][n];
|
|---|
| 676 |
|
|---|
| 677 | for(i=0;i<n;i++)
|
|---|
| 678 | {
|
|---|
| 679 | for(j=0;j<n;j++)
|
|---|
| 680 | {
|
|---|
| 681 | scanf("%d",&mat[i][j]);
|
|---|
| 682 | }
|
|---|
| 683 | }
|
|---|
| 684 |
|
|---|
| 685 | for(i=0;i<n;i++)
|
|---|
| 686 | {
|
|---|
| 687 | for(j=0;j<n;j++)
|
|---|
| 688 | {
|
|---|
| 689 | a=mat[i][j];
|
|---|
| 690 |
|
|---|
| 691 | if(i%2==0 && j%2!=0)
|
|---|
| 692 | {
|
|---|
| 693 | suma+=a;
|
|---|
| 694 | }
|
|---|
| 695 |
|
|---|
| 696 | if(i%2!=0 && j%2==0)
|
|---|
| 697 | {
|
|---|
| 698 | suma+=a;
|
|---|
| 699 | }
|
|---|
| 700 | }
|
|---|
| 701 | }
|
|---|
| 702 |
|
|---|
| 703 | for(k=0;k<n;k++)
|
|---|
| 704 | {
|
|---|
| 705 | mat[k][k]=suma; // za sporedna mat[k][dolzina - k - 1] (obratnoto od k)
|
|---|
| 706 | }
|
|---|
| 707 |
|
|---|
| 708 | for(i=0;i<n;i++)
|
|---|
| 709 | {
|
|---|
| 710 | for(j=0;j<n;j++)
|
|---|
| 711 | {
|
|---|
| 712 | printf("%d ",mat[i][j]);
|
|---|
| 713 | }
|
|---|
| 714 | printf("\n");
|
|---|
| 715 | }
|
|---|
| 716 |
|
|---|
| 717 | return 0;
|
|---|
| 718 | }
|
|---|
| 719 | sporedna dijag. nad pod sobiranja
|
|---|
| 720 | #include <stdio.h>
|
|---|
| 721 | #include <stdlib.h>
|
|---|
| 722 |
|
|---|
| 723 | int main()
|
|---|
| 724 | {
|
|---|
| 725 |
|
|---|
| 726 | int m,n,i,j,a,sumamin=9999,sumamax=0;
|
|---|
| 727 | scanf ("%d%d",&m,&n);
|
|---|
| 728 | int mat[50][50];
|
|---|
| 729 |
|
|---|
| 730 | for(i=0;i<m;i++)
|
|---|
| 731 | {
|
|---|
| 732 | for(j=0;j<n;j++)
|
|---|
| 733 | {
|
|---|
| 734 | scanf ("%d",&mat[i][j]);
|
|---|
| 735 | }
|
|---|
| 736 | }
|
|---|
| 737 | for(i=0;i<m;i++)
|
|---|
| 738 | {
|
|---|
| 739 | for(j=0;j<n;j++)
|
|---|
| 740 | {
|
|---|
| 741 | a=mat[i][j];
|
|---|
| 742 | if (i+j<n-1)
|
|---|
| 743 | {
|
|---|
| 744 | if(sumamin>a)
|
|---|
| 745 | {
|
|---|
| 746 | sumamin=a;
|
|---|
| 747 | }
|
|---|
| 748 | }
|
|---|
| 749 |
|
|---|
| 750 | if(i+j>n-1)
|
|---|
| 751 | {
|
|---|
| 752 | if(sumamax<a)
|
|---|
| 753 | {
|
|---|
| 754 | sumamax=a;
|
|---|
| 755 | }
|
|---|
| 756 | }
|
|---|
| 757 |
|
|---|
| 758 | }
|
|---|
| 759 | }
|
|---|
| 760 | int suma=sumamax+sumamin;
|
|---|
| 761 |
|
|---|
| 762 | for(i=0;i<m;i++)
|
|---|
| 763 | {
|
|---|
| 764 | for(j=0;j<n;j++)
|
|---|
| 765 | {
|
|---|
| 766 | if(i+j==n-1)
|
|---|
| 767 | {
|
|---|
| 768 | mat[i][j]=suma;
|
|---|
| 769 | }
|
|---|
| 770 | }
|
|---|
| 771 | }
|
|---|
| 772 |
|
|---|
| 773 | for(i=0;i<m;i++)
|
|---|
| 774 | {
|
|---|
| 775 | for(j=0;j<n;j++)
|
|---|
| 776 | {
|
|---|
| 777 | printf ("%d ",mat[i][j]);
|
|---|
| 778 | }
|
|---|
| 779 | printf ("\n");
|
|---|
| 780 | }
|
|---|
| 781 |
|
|---|
| 782 | return 0;
|
|---|
| 783 | }
|
|---|
| 784 | zamena na elementi pod i nad glavna dijagonala
|
|---|
| 785 | #include <stdio.h>
|
|---|
| 786 | #include <stdlib.h>
|
|---|
| 787 |
|
|---|
| 788 | int main()
|
|---|
| 789 | {
|
|---|
| 790 | int n,i,j,k,t;
|
|---|
| 791 | scanf("%d",&n);
|
|---|
| 792 | int mat[n][n];
|
|---|
| 793 |
|
|---|
| 794 | for(i=0;i<n;i++)
|
|---|
| 795 | {
|
|---|
| 796 | for(j=0;j<n;j++)
|
|---|
| 797 | {
|
|---|
| 798 | scanf("%d",&mat[i][j]);
|
|---|
| 799 | }
|
|---|
| 800 | }
|
|---|
| 801 |
|
|---|
| 802 | for(k=0;k<n/2;k++)
|
|---|
| 803 | {
|
|---|
| 804 | int temp = mat[k][k];
|
|---|
| 805 | mat[k][k] = mat[n-k-1][n-k-1];
|
|---|
| 806 | mat[n-k-1][n-k-1] = temp;
|
|---|
| 807 | }
|
|---|
| 808 |
|
|---|
| 809 |
|
|---|
| 810 | for(i=0;i<n;i++)
|
|---|
| 811 | {
|
|---|
| 812 | for(j=0;j<n;j++)
|
|---|
| 813 | {
|
|---|
| 814 | if(i<j)
|
|---|
| 815 | {
|
|---|
| 816 | for(t=0;t<n;t++)
|
|---|
| 817 | {
|
|---|
| 818 | for(k=0;k<n;k++)
|
|---|
| 819 | {
|
|---|
| 820 | if(t<k&&mat[i][j]<mat[t][k])
|
|---|
| 821 | {
|
|---|
| 822 | int temp = mat[i][j];
|
|---|
| 823 | mat[i][j] = mat[t][k];
|
|---|
| 824 | mat[t][k] = temp;
|
|---|
| 825 | }
|
|---|
| 826 | }
|
|---|
| 827 | }
|
|---|
| 828 | }
|
|---|
| 829 |
|
|---|
| 830 |
|
|---|
| 831 | if(i>j)
|
|---|
| 832 | {
|
|---|
| 833 | for(t=0;t<n;t++)
|
|---|
| 834 | {
|
|---|
| 835 | for(k=0;k<n;k++)
|
|---|
| 836 | {
|
|---|
| 837 | if(t>k && mat[i][j]>mat[t][k])
|
|---|
| 838 | {
|
|---|
| 839 | int temp = mat[i][j];
|
|---|
| 840 | mat[i][j] = mat[t][k];
|
|---|
| 841 | mat[t][k] = temp;
|
|---|
| 842 | }
|
|---|
| 843 | }
|
|---|
| 844 | }
|
|---|
| 845 | }
|
|---|
| 846 |
|
|---|
| 847 |
|
|---|
| 848 |
|
|---|
| 849 |
|
|---|
| 850 | }
|
|---|
| 851 | }
|
|---|
| 852 |
|
|---|
| 853 | for(i=0;i<n;i++)
|
|---|
| 854 | {
|
|---|
| 855 | for(j=0;j<n;j++)
|
|---|
| 856 | {
|
|---|
| 857 | printf("%2d ",mat[i][j]);
|
|---|
| 858 | }
|
|---|
| 859 | printf("\n");
|
|---|
| 860 | }
|
|---|
| 861 |
|
|---|
| 862 | return 0;
|
|---|
| 863 | }
|
|---|
| 864 | zamena na elem. na glavna dijag. so suma na beli polinja
|
|---|
| 865 | #include <stdio.h>
|
|---|
| 866 | #include <stdlib.h>
|
|---|
| 867 |
|
|---|
| 868 | int main()
|
|---|
| 869 | {
|
|---|
| 870 | int n,i,j,suma=0,k,a;
|
|---|
| 871 | scanf("%d",&n);
|
|---|
| 872 | int mat[n][n];
|
|---|
| 873 |
|
|---|
| 874 | for(i=0;i<n;i++)
|
|---|
| 875 | {
|
|---|
| 876 | for(j=0;j<n;j++)
|
|---|
| 877 | {
|
|---|
| 878 | scanf("%d",&mat[i][j]);
|
|---|
| 879 | }
|
|---|
| 880 | }
|
|---|
| 881 |
|
|---|
| 882 | for(i=0;i<n;i++)
|
|---|
| 883 | {
|
|---|
| 884 | for(j=0;j<n;j++)
|
|---|
| 885 | {
|
|---|
| 886 | a=mat[i][j];
|
|---|
| 887 |
|
|---|
| 888 | if(i%2==0 && j%2!=0)
|
|---|
| 889 | {
|
|---|
| 890 | suma+=a;
|
|---|
| 891 | }
|
|---|
| 892 |
|
|---|
| 893 | if(i%2!=0 && j%2==0)
|
|---|
| 894 | {
|
|---|
| 895 | suma+=a;
|
|---|
| 896 | }
|
|---|
| 897 | }
|
|---|
| 898 | }
|
|---|
| 899 |
|
|---|
| 900 | for(k=0;k<n;k++)
|
|---|
| 901 | {
|
|---|
| 902 | mat[k][k]=suma; // za sporedna mat[k][dolzina - k - 1] (obratnoto od k)
|
|---|
| 903 | }
|
|---|
| 904 |
|
|---|
| 905 | for(i=0;i<n;i++)
|
|---|
| 906 | {
|
|---|
| 907 | for(j=0;j<n;j++)
|
|---|
| 908 | {
|
|---|
| 909 | printf("%d ",mat[i][j]);
|
|---|
| 910 | }
|
|---|
| 911 | printf("\n");
|
|---|
| 912 | }
|
|---|
| 913 |
|
|---|
| 914 | return 0;
|
|---|
| 915 | }
|
|---|
| 916 | zamena na ele. od spore. dija
|
|---|
| 917 | #include <stdio.h>
|
|---|
| 918 | #include <stdlib.h>
|
|---|
| 919 |
|
|---|
| 920 | int main()
|
|---|
| 921 | {
|
|---|
| 922 |
|
|---|
| 923 | int m,n,i,j,a,sumamin=9999,sumamax=0;
|
|---|
| 924 | scanf ("%d%d",&m,&n);
|
|---|
| 925 | int mat[50][50];
|
|---|
| 926 |
|
|---|
| 927 | for(i=0;i<m;i++)
|
|---|
| 928 | {
|
|---|
| 929 | for(j=0;j<n;j++)
|
|---|
| 930 | {
|
|---|
| 931 | scanf ("%d",&mat[i][j]);
|
|---|
| 932 | }
|
|---|
| 933 | }
|
|---|
| 934 | for(i=0;i<m;i++)
|
|---|
| 935 | {
|
|---|
| 936 | for(j=0;j<n;j++)
|
|---|
| 937 | {
|
|---|
| 938 | a=mat[i][j];
|
|---|
| 939 | if (i+j<n-1)
|
|---|
| 940 | {
|
|---|
| 941 | if(sumamin>a)
|
|---|
| 942 | {
|
|---|
| 943 | sumamin=a;
|
|---|
| 944 | }
|
|---|
| 945 | }
|
|---|
| 946 |
|
|---|
| 947 | if(i+j>n-1)
|
|---|
| 948 | {
|
|---|
| 949 | if(sumamax<a)
|
|---|
| 950 | {
|
|---|
| 951 | sumamax=a;
|
|---|
| 952 | }
|
|---|
| 953 | }
|
|---|
| 954 |
|
|---|
| 955 | }
|
|---|
| 956 | }
|
|---|
| 957 | int suma=sumamax+sumamin;
|
|---|
| 958 |
|
|---|
| 959 | for(i=0;i<m;i++)
|
|---|
| 960 | {
|
|---|
| 961 | for(j=0;j<n;j++)
|
|---|
| 962 | {
|
|---|
| 963 | if(i+j==n-1)
|
|---|
| 964 | {
|
|---|
| 965 | mat[i][j]=suma;
|
|---|
| 966 | }
|
|---|
| 967 | }
|
|---|
| 968 | }
|
|---|
| 969 |
|
|---|
| 970 | for(i=0;i<m;i++)
|
|---|
| 971 | {
|
|---|
| 972 | for(j=0;j<n;j++)
|
|---|
| 973 | {
|
|---|
| 974 | printf ("%d ",mat[i][j]);
|
|---|
| 975 | }
|
|---|
| 976 | printf ("\n");
|
|---|
| 977 | }
|
|---|
| 978 |
|
|---|
| 979 | return 0;
|
|---|
| 980 | }
|
|---|
| 981 | razlika na suma od red i kolona
|
|---|
| 982 | #include <stdio.h>
|
|---|
| 983 | #include <stdlib.h>
|
|---|
| 984 |
|
|---|
| 985 | int main()
|
|---|
| 986 | {
|
|---|
| 987 | int i,j,m,n,a,razlika,k;
|
|---|
| 988 | scanf("%d%d",&m,&n);
|
|---|
| 989 | int mat[m][n];
|
|---|
| 990 | int mat2[m][n];
|
|---|
| 991 |
|
|---|
| 992 | for(i=0;i<m;i++)
|
|---|
| 993 | {
|
|---|
| 994 | for(j=0;j<n;j++)
|
|---|
| 995 | {
|
|---|
| 996 | scanf("%d",&mat[i][j]);
|
|---|
| 997 | }
|
|---|
| 998 | }
|
|---|
| 999 |
|
|---|
| 1000 | for(i=0;i<m;i++)
|
|---|
| 1001 | {
|
|---|
| 1002 | for(j=0;j<n;j++)
|
|---|
| 1003 | {
|
|---|
| 1004 | a=mat[i][j];
|
|---|
| 1005 | int suma_red=0;
|
|---|
| 1006 | int suma_kol=0;
|
|---|
| 1007 |
|
|---|
| 1008 | for(k=0;k<n;k++)
|
|---|
| 1009 | {
|
|---|
| 1010 | suma_red+=mat[i][k];
|
|---|
| 1011 | }
|
|---|
| 1012 |
|
|---|
| 1013 | for(k=0;k<m;k++)
|
|---|
| 1014 | {
|
|---|
| 1015 | suma_kol+=mat[k][j];
|
|---|
| 1016 | }
|
|---|
| 1017 |
|
|---|
| 1018 | suma_red-=a;
|
|---|
| 1019 | suma_kol-=a;
|
|---|
| 1020 |
|
|---|
| 1021 | razlika=suma_red - suma_kol;
|
|---|
| 1022 |
|
|---|
| 1023 | mat2[i][j] = razlika;
|
|---|
| 1024 |
|
|---|
| 1025 | }
|
|---|
| 1026 | }
|
|---|
| 1027 |
|
|---|
| 1028 | for(i=0;i<m;i++)
|
|---|
| 1029 | {
|
|---|
| 1030 | for(j=0;j<n;j++)
|
|---|
| 1031 | {
|
|---|
| 1032 | printf("%d ",mat2[i][j]);
|
|---|
| 1033 | }
|
|---|
| 1034 | printf("\n");
|
|---|
| 1035 | }
|
|---|
| 1036 |
|
|---|
| 1037 | return 0;
|
|---|
| 1038 | }
|
|---|
| 1039 | zemena na sekoj element so zbir na red i kol.
|
|---|
| 1040 | #include <stdio.h>
|
|---|
| 1041 | #include <stdlib.h>
|
|---|
| 1042 |
|
|---|
| 1043 | int main()
|
|---|
| 1044 | {
|
|---|
| 1045 | int m,n,i,j,a,k;
|
|---|
| 1046 | scanf ("%d%d",&m,&n);
|
|---|
| 1047 | int mat[m][n];
|
|---|
| 1048 | int mat2[m][n];
|
|---|
| 1049 |
|
|---|
| 1050 | for(i=0;i<m;i++)
|
|---|
| 1051 | {
|
|---|
| 1052 | for(j=0;j<n;j++)
|
|---|
| 1053 | {
|
|---|
| 1054 | scanf ("%d", &mat[i][j]);
|
|---|
| 1055 | }
|
|---|
| 1056 | }
|
|---|
| 1057 |
|
|---|
| 1058 | for(i=0;i<m;i++)
|
|---|
| 1059 | {
|
|---|
| 1060 | for(j=0;j<n;j++)
|
|---|
| 1061 | {
|
|---|
| 1062 | a=mat[i][j];
|
|---|
| 1063 | int suma=0;
|
|---|
| 1064 | for (k=0;k<n;k++)
|
|---|
| 1065 | {
|
|---|
| 1066 |
|
|---|
| 1067 | suma+= mat[i][k];
|
|---|
| 1068 | }
|
|---|
| 1069 |
|
|---|
| 1070 | for(k=0;k<m;k++)
|
|---|
| 1071 | {
|
|---|
| 1072 | suma+=mat[k][j];
|
|---|
| 1073 | }
|
|---|
| 1074 |
|
|---|
| 1075 | suma=suma-a-a;//suma-=2*a;
|
|---|
| 1076 |
|
|---|
| 1077 |
|
|---|
| 1078 | mat2[i][j]=suma;
|
|---|
| 1079 |
|
|---|
| 1080 |
|
|---|
| 1081 | }
|
|---|
| 1082 | }
|
|---|
| 1083 | for(i=0;i<m;i++)
|
|---|
| 1084 | {
|
|---|
| 1085 | for(j=0;j<n;j++)
|
|---|
| 1086 | {
|
|---|
| 1087 | printf ("%d ",mat2[i][j]);
|
|---|
| 1088 | }
|
|---|
| 1089 | printf ("\n");
|
|---|
| 1090 | }
|
|---|
| 1091 |
|
|---|
| 1092 | return 0;
|
|---|
| 1093 | }
|
|---|
| 1094 | min suma pod glavna dijag.
|
|---|
| 1095 | #include <stdio.h>
|
|---|
| 1096 | #include <stdlib.h>
|
|---|
| 1097 |
|
|---|
| 1098 | int main()
|
|---|
| 1099 | {
|
|---|
| 1100 | int n,i,j,k,sumamin=9999,suma=0;
|
|---|
| 1101 | scanf("%d",&n);
|
|---|
| 1102 | int mat[n][n];
|
|---|
| 1103 |
|
|---|
| 1104 | for(i=0;i<n;i++)
|
|---|
| 1105 | {
|
|---|
| 1106 | for(j=0;j<n;j++)
|
|---|
| 1107 | {
|
|---|
| 1108 | scanf("%d",&mat[i][j]);
|
|---|
| 1109 | }
|
|---|
| 1110 | }
|
|---|
| 1111 |
|
|---|
| 1112 | for(k=n;k>0;k--)
|
|---|
| 1113 | {
|
|---|
| 1114 | suma=0;
|
|---|
| 1115 | for(i=0;i<k;i++)
|
|---|
| 1116 | {
|
|---|
| 1117 | suma+=mat[n-k+i][i];
|
|---|
| 1118 |
|
|---|
| 1119 |
|
|---|
| 1120 | }
|
|---|
| 1121 | if(sumamin > suma)
|
|---|
| 1122 | {
|
|---|
| 1123 | sumamin=suma;
|
|---|
| 1124 | }
|
|---|
| 1125 |
|
|---|
| 1126 | }
|
|---|
| 1127 |
|
|---|
| 1128 | printf("%d",sumamin);
|
|---|
| 1129 | return 0;
|
|---|
| 1130 | }
|
|---|
| 1131 | zbir na dija.2
|
|---|
| 1132 | #include <stdio.h>
|
|---|
| 1133 | #include <stdlib.h>
|
|---|
| 1134 |
|
|---|
| 1135 | int main()
|
|---|
| 1136 | {
|
|---|
| 1137 | int i,j,n,k,sumamin=9999,suma=0;
|
|---|
| 1138 | scanf("%d",&n);
|
|---|
| 1139 | int mat[n][n];
|
|---|
| 1140 |
|
|---|
| 1141 | for(i=0;i<n;i++)
|
|---|
| 1142 | {
|
|---|
| 1143 | for(j=0;j<n;j++)
|
|---|
| 1144 | {
|
|---|
| 1145 | scanf("%d",&mat[i][j]);
|
|---|
| 1146 | }
|
|---|
| 1147 | }
|
|---|
| 1148 |
|
|---|
| 1149 | for(k=n;k>0;k--)
|
|---|
| 1150 | {
|
|---|
| 1151 | suma=0;
|
|---|
| 1152 | for(i=0;i<k;i++)
|
|---|
| 1153 | {
|
|---|
| 1154 | suma+=mat[n-k+i][k-i-1 + (n-k)];
|
|---|
| 1155 | }
|
|---|
| 1156 |
|
|---|
| 1157 | if(sumamin > suma)
|
|---|
| 1158 | {
|
|---|
| 1159 | sumamin=suma;
|
|---|
| 1160 | }
|
|---|
| 1161 | }
|
|---|
| 1162 |
|
|---|
| 1163 | printf("%d",sumamin);
|
|---|
| 1164 |
|
|---|
| 1165 |
|
|---|
| 1166 | return 0;
|
|---|
| 1167 | }
|
|---|
| 1168 | zbir na sosedni elem.
|
|---|
| 1169 | #include <stdio.h>
|
|---|
| 1170 | #include <stdlib.h>
|
|---|
| 1171 | int main()
|
|---|
| 1172 | {
|
|---|
| 1173 | int m,n,i,j,a,suma=0;
|
|---|
| 1174 | scanf ("%d%d",&m,&n);
|
|---|
| 1175 |
|
|---|
| 1176 | int mat[m][n];
|
|---|
| 1177 | int mat2[m][n];
|
|---|
| 1178 |
|
|---|
| 1179 |
|
|---|
| 1180 | for (i=0;i<m;i++)
|
|---|
| 1181 | {
|
|---|
| 1182 | for(j=0;j<n;j++)
|
|---|
| 1183 | {
|
|---|
| 1184 | scanf("%d",&mat[i][j]);
|
|---|
| 1185 | mat2[i][j]=mat[i][j];
|
|---|
| 1186 | }
|
|---|
| 1187 | }
|
|---|
| 1188 |
|
|---|
| 1189 | for (i=0;i<m;i++)
|
|---|
| 1190 | {
|
|---|
| 1191 |
|
|---|
| 1192 | for(j=0;j<n;j++)
|
|---|
| 1193 | {
|
|---|
| 1194 | suma=0;
|
|---|
| 1195 | a=mat[i][j];
|
|---|
| 1196 |
|
|---|
| 1197 | if (i > 0&&(a<mat[i-1][j])){ //Goren element
|
|---|
| 1198 |
|
|---|
| 1199 | suma=suma+mat[i-1][j];
|
|---|
| 1200 | }
|
|---|
| 1201 |
|
|---|
| 1202 | if( i < m-1 && (a<mat[i+1][j])) //DOlen element
|
|---|
| 1203 | {
|
|---|
| 1204 | suma+=mat[i+1][j];
|
|---|
| 1205 | }
|
|---|
| 1206 |
|
|---|
| 1207 | if( j > 0 && (a<mat[i][j-1])) //Lev element
|
|---|
| 1208 | {
|
|---|
| 1209 | suma+=mat[i][j-1];
|
|---|
| 1210 | }
|
|---|
| 1211 |
|
|---|
| 1212 | if( j < n - 1 && (a<mat[i][j+1])) // Desen element
|
|---|
| 1213 | {
|
|---|
| 1214 | suma+=mat[i][j+1];
|
|---|
| 1215 | }
|
|---|
| 1216 |
|
|---|
| 1217 | mat2[i][j]=suma;
|
|---|
| 1218 |
|
|---|
| 1219 | }
|
|---|
| 1220 | }
|
|---|
| 1221 |
|
|---|
| 1222 | for(i=0;i<m;i++)
|
|---|
| 1223 | {
|
|---|
| 1224 | for(j=0;j<n;j++)
|
|---|
| 1225 | {
|
|---|
| 1226 | printf ("%d ",mat2[i][j]);
|
|---|
| 1227 | }
|
|---|
| 1228 | printf ("\n");
|
|---|
| 1229 | }
|
|---|
| 1230 |
|
|---|
| 1231 |
|
|---|
| 1232 |
|
|---|
| 1233 | return 0;
|
|---|
| 1234 | }
|
|---|
| 1235 | promena an mesta min i maks
|
|---|
| 1236 | #include <stdio.h>
|
|---|
| 1237 | #include <stdlib.h>
|
|---|
| 1238 |
|
|---|
| 1239 | int main()
|
|---|
| 1240 | {
|
|---|
| 1241 | int m,n,i,j,min_suma=9999,max_suma=-9999,a,maxred,minred,suma;
|
|---|
| 1242 | scanf("%d%d",&m,&n);
|
|---|
| 1243 | int mat[m][n];
|
|---|
| 1244 |
|
|---|
| 1245 | for(i=0;i<m;i++)
|
|---|
| 1246 | {
|
|---|
| 1247 | for(j=0;j<n;j++)
|
|---|
| 1248 | {
|
|---|
| 1249 | scanf("%d",&mat[i][j]);
|
|---|
| 1250 | }
|
|---|
| 1251 | }
|
|---|
| 1252 |
|
|---|
| 1253 | for(i=0;i<m;i++)
|
|---|
| 1254 | {
|
|---|
| 1255 | suma = 0;
|
|---|
| 1256 | for(j=0;j<n;j++)
|
|---|
| 1257 | {
|
|---|
| 1258 | a=mat[i][j];
|
|---|
| 1259 | suma+=a;
|
|---|
| 1260 |
|
|---|
| 1261 |
|
|---|
| 1262 |
|
|---|
| 1263 | }
|
|---|
| 1264 |
|
|---|
| 1265 | if(max_suma<suma)
|
|---|
| 1266 | {
|
|---|
| 1267 | max_suma=suma;
|
|---|
| 1268 | maxred=i;
|
|---|
| 1269 | }
|
|---|
| 1270 |
|
|---|
| 1271 | if(min_suma>suma)
|
|---|
| 1272 | {
|
|---|
| 1273 | min_suma=suma;
|
|---|
| 1274 | minred=i;
|
|---|
| 1275 | }
|
|---|
| 1276 | }
|
|---|
| 1277 |
|
|---|
| 1278 | for(j=0;j<n;j++)
|
|---|
| 1279 | {
|
|---|
| 1280 | int temp=mat[maxred][j];
|
|---|
| 1281 | mat[maxred][j]=mat[minred][j];
|
|---|
| 1282 | mat[minred][j]=temp;
|
|---|
| 1283 | }
|
|---|
| 1284 |
|
|---|
| 1285 | for(i=0;i<m;i++)
|
|---|
| 1286 | {
|
|---|
| 1287 | for(j=0;j<n;j++)
|
|---|
| 1288 | {
|
|---|
| 1289 | printf("%d ",mat[i][j]);
|
|---|
| 1290 | }
|
|---|
| 1291 | printf("\n");
|
|---|
| 1292 | }
|
|---|
| 1293 | return 0;
|
|---|
| 1294 | }
|
|---|
| 1295 | promenea na kol min i maks
|
|---|
| 1296 | #include <stdio.h>
|
|---|
| 1297 | #include <stdlib.h>
|
|---|
| 1298 |
|
|---|
| 1299 | int main()
|
|---|
| 1300 | {
|
|---|
| 1301 | int m,n,i,j,sumamin=9999,sumamax=0,a,kol_max,kol_min;
|
|---|
| 1302 | scanf("%d%d",&m,&n);
|
|---|
| 1303 | int mat[m][n];
|
|---|
| 1304 | for(i=0;i<m;i++)
|
|---|
| 1305 | {
|
|---|
| 1306 | for(j=0;j<n;j++)
|
|---|
| 1307 | {
|
|---|
| 1308 | scanf ("%d",&mat[i][j]);
|
|---|
| 1309 | }
|
|---|
| 1310 | }
|
|---|
| 1311 |
|
|---|
| 1312 | for(j=0;j<n;j++)
|
|---|
| 1313 | {
|
|---|
| 1314 | int suma=0;
|
|---|
| 1315 | for(i=0;i<m;i++)
|
|---|
| 1316 | {
|
|---|
| 1317 | a=mat[i][j];
|
|---|
| 1318 | suma+=a;
|
|---|
| 1319 | }
|
|---|
| 1320 |
|
|---|
| 1321 | if(sumamin>suma)
|
|---|
| 1322 | {
|
|---|
| 1323 | sumamin=suma;
|
|---|
| 1324 | kol_min=j;
|
|---|
| 1325 | }
|
|---|
| 1326 |
|
|---|
| 1327 | if(sumamax<suma)
|
|---|
| 1328 | {
|
|---|
| 1329 | sumamax=suma;
|
|---|
| 1330 | kol_max=j;
|
|---|
| 1331 | }
|
|---|
| 1332 | }
|
|---|
| 1333 |
|
|---|
| 1334 | for(i=0;i<m;i++)
|
|---|
| 1335 | {
|
|---|
| 1336 | int temp = mat[i][kol_min];
|
|---|
| 1337 | mat[i][kol_min]= mat[i][kol_max];
|
|---|
| 1338 | mat[i][kol_max]=temp;
|
|---|
| 1339 | }
|
|---|
| 1340 |
|
|---|
| 1341 | for (i=0;i<m;i++)
|
|---|
| 1342 | {
|
|---|
| 1343 | for(j=0;j<n;j++)
|
|---|
| 1344 | {
|
|---|
| 1345 | printf ("%d ",mat[i][j]);
|
|---|
| 1346 | }
|
|---|
| 1347 | printf ("\n");
|
|---|
| 1348 | }
|
|---|
| 1349 |
|
|---|
| 1350 | return 0;
|
|---|
| 1351 | }
|
|---|