שפת סי
Question:

כתוב תוכנית אשר קולטת שני מספרים (אחד לעמודה אחד לשורה),מקצה שני מערכים דו מימדיים כגודל הקלט . 

בנה פונקציה שמחשבת את סכום המערכים ובודקת אם הם שווים .

אם כן הדפס את מערך 

אם לא הדפס את "מערכים לא שווים"

Provide an answer by clicking on "Map" and then on "Add an Answer".



Results, Analysis and Discussion


Comments:
1.  moyal mor (24.11.2016 am 11.41.00)
פתרון

#include <stdio.h>

#include <conio.h>

#include <malloc.h>

#include <stdlib.h>

 

int SumAlahso(int n, int m, int **arr1, int **arr2)

{

       int i, j, sum1 = 0, sum2 = 0;

 

       for (i = 0; i < m; i++)

              for (j = 0; j < n; j++)

                     sum1 = sum1 + arr1[i][j];

 

       for (i = 0; i < m; i++)

              for (j = 0; j < n; j++)

                     sum2 = sum2 + arr2[i][j];

 

       if (sum1 == sum2)

              for (i = 0; i < m; i++)

              {

                     for (j = i; j < n; j++)

                           printf(" %d", arr1[i][j]);

                     printf(" ");

              }

       else

       {

              printf("the sum of arr not equle");

       }

}

 

void main()

{

       int **p, **p2, i, j, n, m;

 

       scanf("enter m:%d n:%d", &m, &n);

 

       p = (int **)malloc(m * sizeof(int *));

       if (p == NULL)

       {

              printf("Error");

              getch();

              exit(1);

       }

       for (i = 0; i<m; i++)

       {

              p[i] = (int *)malloc(n * sizeof(int *));

              if (p == NULL) 

              {

                     for (j = 0; j<i; j++) free(p[j]);

                     free(p);

                     printf("Error in allocating the memory");

                     _getch();

                     exit(1);

              }

       }

       for (i = 0; i<m; i++)

              for (j = 0; j<n; j++)

                     scanf(&p[i][j]);

 

 

       p2 = (int **)malloc(m * sizeof(int *));

       if (p2 == NULL)

       {

              printf("Error");

              getch();

              exit(1);

       }

       for (i = 0; i<m; i++)

       {

              p2[i] = (int *)malloc(n * sizeof(int *));

              if (p2 == NULL)

              {

                     for (j = 0; j<i; j++) free(p[j]);

                     free(p2);

                     printf("Error in allocating the memory");

                     _getch();

                     exit(1);

              }

       }

       for (i = 0; i<m; i++)

              for (j = 0; j<n; j++)

                     scanf(&p2[i][j]);

 

       SumAlahson(n, m, p, p2);

 

       for (i = 0; i < m; i++)

       {

              free(p[i]);

              free(p2[i]);

       }

       free(p);

       free(p2);

 

       _getch();

}

 



History of edits
More Interactive Questions that might interest you In Computer