Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- int mat[50][50], n, m;
- void citire() {
- printf("n=");
- scanf("%d", &n);
- printf("m=");
- scanf("%d", &m);
- for (int i = 0; i<n; i++)
- for (int j = 0; j < m; j++) {
- printf("mat[%d][%d] = ", i, j);
- scanf("%d", &mat[i][j]);
- }
- }
- void afisare() {
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++)
- printf("%d ", mat[i][j]);
- printf("\n");
- }
- }
- void main() {
- int i = 0, j = 0, nr1, nr2;
- citire();
- for (i = 0; i<n; i++)
- for (j = 0; j < m; j++) {
- if (i == 0 && j > 0)
- mat[i][j] = mat[i][j] + mat[i][j - 1];
- else
- if (j == 0 && i > 0)
- mat[i][j] += mat[i - 1][j];
- else {
- if ((j > 0) && (i > 0)) {
- nr1 = mat[i][j] + mat[i][j - 1];
- nr2 = mat[i][j] + mat[i - 1][j];
- if (nr1 > nr2)
- mat[i][j] = nr1;
- else
- mat[i][j] = nr2;
- }
- }
- }
- afisare();
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement