Za sve sam imao resenje osim za ovaj zadatak gde se objasnjava Variable-Length Arrays.
Ostavicu kod i obeleziti sta ne razumem, pa se nadam da ce se neko javiti i pomoci.
Code:
#include <stdio.h>
#include <stdlib.h>
#define ROW 3
#define COLS 4
int sum2d(int rows, int cols, int ar[rows][cols]);
int main()
{
int i,j;
int rs = 3;
int cs = 10;
int varr[rs][cs];
int junk[ROW][COLS]= {{2,4,6,8},{3,5,7,9},{12,10,8,6}};
int more_junk[ROW-1][COLS+2]={{20,30,40,50,60,70},{5,6,7,8,9,10}};
for(i=0;i<rs;i++)
for(j=0;j<cs;j++)
varr[i][j] = i * j+j; /*OVAJ DEO MI NIJE JASAN, STA PREDSTAVLJA "I*J+J" */
printf("3x5 array\n");
printf("Sum of all elements = %d \n",sum2d(ROW,COLS,junk));
printf("2x6 array\n");
printf("Sum of all elemnts = %d\n",sum2d(ROW-1, COLS+2,more_junk));
printf("3x10 VLA \n");
printf("Sum of all elemnts = %d\n",sum2d(rs,cs,varr)); /*REZUTLAT OVE FUNKCIJE BUDE 270??? KAKO SE DOBIJA TAJ REZULTAT?*/
return 0;
}
int sum2d(int rows, int cols, int ar[rows][cols])
{
int r,c;
int total =0;
for(r=0;r<rows;r++)
for(c=0;c<cols;c++)
total += ar[r][c];
return total;
}
#include <stdio.h>
#include <stdlib.h>
#define ROW 3
#define COLS 4
int sum2d(int rows, int cols, int ar[rows][cols]);
int main()
{
int i,j;
int rs = 3;
int cs = 10;
int varr[rs][cs];
int junk[ROW][COLS]= {{2,4,6,8},{3,5,7,9},{12,10,8,6}};
int more_junk[ROW-1][COLS+2]={{20,30,40,50,60,70},{5,6,7,8,9,10}};
for(i=0;i<rs;i++)
for(j=0;j<cs;j++)
varr[i][j] = i * j+j; /*OVAJ DEO MI NIJE JASAN, STA PREDSTAVLJA "I*J+J" */
printf("3x5 array\n");
printf("Sum of all elements = %d \n",sum2d(ROW,COLS,junk));
printf("2x6 array\n");
printf("Sum of all elemnts = %d\n",sum2d(ROW-1, COLS+2,more_junk));
printf("3x10 VLA \n");
printf("Sum of all elemnts = %d\n",sum2d(rs,cs,varr)); /*REZUTLAT OVE FUNKCIJE BUDE 270??? KAKO SE DOBIJA TAJ REZULTAT?*/
return 0;
}
int sum2d(int rows, int cols, int ar[rows][cols])
{
int r,c;
int total =0;
for(r=0;r<rows;r++)
for(c=0;c<cols;c++)
total += ar[r][c];
return total;
}