0 like 0 dislike
2.4k views

Please write a program receive 2 sets of two-dimensional arrays: a[ ][ ] and b[ ][ ]; size 3*3. Then add a value of each element from a to b for example: a[0][0] + b[0][0], a[0][1] + b[0][1] and so on. Finally, output the summation of each addition.

For more information: http://pipls.net/41053/multi-dimensional-arrays-in-c-language

Input 1

1 2 3
4 5 6
7 8 9
1 1 1
1 1 1
1 1 1

Output 1

1 2 3
4 5 6
7 8 9
1 1 1
1 1 1
1 1 1
2 3 4
5 6 7
8 9 10

Input 2

1 1 1
0 0 0
1 1 1
2 2 2
2 2 2
2 2 2

Output 2

1 1 1
0 0 0
1 1 1
2 2 2
2 2 2
2 2 2
3 3 3
2 2 2
3 3 3

 

[Exercise] Coding (C) - asked in Chapter 4: Arrays by (5.9k points)
ID: 41054 - Available when: Unlimited - Due to: Unlimited
| 2.4k views

18 Answers

0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    int a[3][3];
* ** * **** * **** b[3][3];
    
* ** * ****** ***** ** (int i=0;i<3;i++){
***** **** ** ** **** * ** ****** * *** * j=0;j<3;j++){
** **** * ** * * ** ** *** ** *** *** *** ***** * ** * * ** ** * ** * ** ******** ** * ,&a[i][j]);
* * * ** * * * ****** * **** * * * * * * *** * * * **** * ** **** ** *** *
** * * ** * * ** * * * *** * *
* ***** ** *** * **** *** * * * ** * * * * * *** * *** **** *** **** * ** *** * ***** * **** * ****** * * (int i=0;i<3;i++){
*** *** * ** *** *** * *** * * ** * ******* ****** j=0;j<3;j++){
* ** * ** * ** ** *** ** *** * * ** * * ******* * ** * ** ******* **** * * *** ** ** ,&b[i][j]);
* * * ** ** *** * * *** * * * ** * ** * * * **** * *** *** ** * ***** * *** ****** *
** * * * ** * * * **** ***** ** * ***** * ** *
* * * **** ** **** * * ** * * * ***** * ** * * **** * * * (int i=0;i<3;i++){
** *** ** **** *** ** * * ** ** *** * * ****** j=0;j<3;j++){
* ** *** ** * ** * * * * ** * * * ** * * ** ** * ** * ** * * ** ** *** ** * * *** ** ** * * " ,a[i][j]+b[i][j]);
*** * **** * * * **** *** * * ** * * * ** * ** * * ********* * ** ****** ** * **
********* ***** * * * ** * * * * * ** **** **** * * ** * * * *** *** **** ***** * ** ** ***** ** * * ***** * *
*** *** * * ** * * * * ***** ** ** **
  
* * * ****** * *** *** * * **  
  return 0;
}
100/100 answered by (227 points)
0 0
Case 0: Correct output
Case 1: Wrong output
Case 2: Wrong output
0 like 0 dislike
Hidden content!
#include * * * * **
 
int main()
{
**** **** *** *** ** * a, b, ***** ** ** ** *****
 
* ******** * * * * ** (a = 0; a < 3; a++)
** ** * * ** * ** * ** ** * (b = 0; b < 3; b++)
*** ***** * **** ******* ** ** * ** ** * * * ** * ******** * * ***
*** *
*** *** * *** * * (a = 0; a < 3; a++)
*** *** ** ** * ** ** ** ** * * * (b = 0 ; b < 3; b++)
* *** ** *** ** *** ** **** *** **** ** *** * * ****** * *** *
* **
 
** ** * ** * * * (a = 0; a < 3; a++) {
* * * ** **** *** ** * *** * * *** (b = 0 ; b < 3; b++) {
*** * * *** ** * ** * ** * * ** ** ** ** * *** = first[a][b] + *
* ***** ** * * * * * ** * * * * **** * * ** ****** ", * ***
** * * **** ** * * * * ** *
* * * **** **** * *** *** *** ***** **** *** ** **
**** * ****
* *** ** ***** ** **
*** ** ** ** ** ** 0;
}
100/100 answered by (183 points)
0 0
Case 0: Correct output
Case 1: Wrong output
Case 2: Wrong output
0 like 0 dislike
Hidden content!
#include * * * ** ***
* ** *
int main()
{
*** ** *** * * a, b, * ** * * * * * * * **
 
***** * *** * *** (a = 0; a < 3; a++)
* *** * * *** ** * ** * * **** **** ******* (b = 0; b < 3; b++)
** * * * * ** * * * ****** ****** * **** ** ** ** * * ** ** ** *** * *
*
** ** * * * ** * * (a = 0; a < 3; a++)
* * *** *** **** * ** * * **** * * *** (b = 0 ; b < 3; b++)
* * * ** * **** **** ** * ** ** * * * ** ** *** * * **** * **** ** * **
***
 
** ** *** ** ** * (a = 0; a < 3; a++) {
** ***** **** ** * * ** * *** (b = 0 ; b < 3; b++) {
* *** * ***** * ** **** ** * **** * * * * * **** ** * * = ***** + * **
* * ******* * * * ** * * ** **** * ** ** *** ** **** *** * *
*** * * *** ** *** ** * ***** **
*** * * * * * * * ** ** *** *** * * **
* ** ** ** ***
   
* *** * ** ** ** 0;
}
100/100 answered by (268 points)
0 1
prog.c: In function 'main':
prog.c:23:3: warning: implicit declaration of function 'system' [-Wimplicit-function-declaration]
   system("PAUSE");
   ^~~~~~
0 1
Case 0: Correct output
Case 1: Wrong output
Case 2: Wrong output
0 like 0 dislike
Hidden content!
#include ** **
#include * * * *

/* run this program using the console pauser or add your own getch, * * ** ***** or input loop */

int main(int argc, char *argv[]) {
* *** * * * int a[3][3] = ** ** * ******* *
* * ** ** ** int b[3][3] = ***** *** **
* ** * *** int i=0;
** * * * **** int j=0;
* * * * *
** * ** ** * * * * * **
*** * ** * * * *** ** *
** * * ** * * ** * ** * * * * * * * * * * * * * * ** *** * * * ****
* ***** *** ** * ***** * *** * *** j++;
** * * * * ** *** }
* *** ** ** ** *** **
**** ** * ****** ** *** i++;
* ** ** ********* }
* * * ***** * i=0;
*** ** * * j=0;
* ** * ** **** * * ** ***** **
***** ** * * ** ** * **
* **** **** ** * ** * **** * ***** ** *** * **** ** ** * *
*** ** * * * ** *** * ** * * * * * ** j++;
**** ** * ** * * ** ** * }
*** * *** * * * ** * * *
*** *** ** * * * ** ** * i++;
* * * * * }
*** **** * *** i=0;
* *** * j=0;
* *** *** while * **
* * ** * * *** ** ** * *** * **
* ** * * * ** ** * * ** ** *** * ** * *
** *** *** * ** * * ** * *** * ** * ** **** ***
* * ** *** * * ** *** * * ** **
* ** * * * * ** * ** ** * * j++;
** * * *** * ** ** ** ** *** *** * * * ** * * *
* ** i++;
** *** * *** ** * ** }
** * ** * }

* * **
*** **** **** return 0;
}
answered by (227 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 like 0 dislike
Hidden content!
#include ***** ** ***
#include ***** ***

/* run this program using the console pauser or add your own getch, * *** ** ** or input loop */

int main(int argc, char *argv[]) {
* **** *   int ** * **
    int ** *
** ** * ** *********** *** * rows = 3;
*** ** * * ** ** ** columns = 3;
** ** * ** * ** ** sum[3][3];
* **** * * * * *
* * * ** ** *** ***
**** *** * * *** the array with some numbers */
* * * * ***** * *** * ** i;
***** * **** ** ** *** ** ****** * a number for 1st ** * *** ***
** *** *** * ** * ** * * = 0; i < rows; i++){
****** * *** **** * * *****   int j;
* ** * *** * * * * * ** * * ** * ** * * ** = 0; j < columns; j++){
*** * * ** * **** * ** ** ** ** ******   ** * %d %d: * * * ** i+1, j+1);
**** *** * * * **** *** * * * * ***       ***** *** *** * * * * ** **
***** * ** * * ** * ** * * * * * ***** **
}
}
***** * * ****** ** *** ** ** = 0; i < rows; i++){
* *** *** ** * *** **   int j;
* * * * * ** *** ** * ** * * ***** * ** = 0; j < columns; j++){
** * *** * * * *** ** * *** ** *** *** ** * * ** **** * * * ** ** * * ** * ", ** **
** **** * **
****** ** * ** ** * ** * ** * *** ** * * ** ****** * **
}
*** ** ** *** * * ********* *** * * *
* * * *** *** * ** ** * * * a number for 2nd * ** **
* *** *** * = 0; i < rows; i++){
* ***** * * * **** ** * *   int j;
* * ** * *** * * ** * *** * **** *** *** *** = 0; j < columns; j++){
** **** * ** * ** * **** ** ** * *** * ** * *** *   * * ** * %d %d: **** i+1, j+1);
** *** * ** * * ***** ***** ** **** ** ** ***       * * ** * ** *** * * ** * **
}
}
* * ** ** * * ** *** * * = 0; i < rows; i++){
**** * * * *** * ** ** ***   int j;
** ** * ** * **** ** ** * * *** ** = 0; j < columns; j++){
* ** * * **** * * * *** ***** * ** * ** ********** ** * ** ** * ** * * ** ** * ******
*** ** * ***** *** * * ** ** ** * ** ** *** ** * ** * * ** * *
**** * * * ** ***** *** ****** ***** * * * ** * * **
* * *** ** * *** * *
**** *** * ***** * *** ** ***** * * ** * *
* * ** ** * *** ** = 0; i < rows; i++){
** * * * **** * * **** *   int j;
** *** **** *** * * *** **** **** * * * * ** = 0; j < columns; j++){
******* * * * ** ** * * * *** ** * *** * *   * ** * *** * + * ***
** * ** ******* * * * **** ** *** * ** * ** *
* ** * * ** ** * ** *** ** * * * *** * * *** * * ** * * * ** * * * * *
*** * ** * * *** * *** * * ** * * * ***** ** ** *** **** ** * **** *** * *
***** *** ** * ** *** * * * ** *** *** * ** * * * * *** * *
* **** ** ****** * ** **
**** * ** * *** ****
* * * * ** *** *
** ** *** * * * *** *
** ***   return 0;
}
100/100 answered by (252 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 like 0 dislike
Hidden content!
#include * ** *
#include * * ** * * ** *

/* run this program using the console pauser or add your own getch, **** * * ** * * ** or input loop */

int main(int argc, char *argv[]) {
    int * ** ** *
    int ** **
* ** ** ** ***** rows = 3;
* ** * * **** **** * * columns = 3;
* * ** ** *** **** * ** sum[3][3];
* ** * *** * * * * *
* ** *** * *
****** *** ********* ** * the array with some numbers */
* * ** ** **** * * *** counterA = 0;
* * * ** * ** ** i;
** *** *** * ** ** * ** = 0; i < rows; i++){
* ** *** ***** * * ** *** *   int j;
** * ***** * * ** * * ******** * ** **** = 0; j < columns; j++){
* ** * * **** * ** ** * ** * **** ** * * ** *** *** * * ** ** * * **** * = counterA++;
}
}
*** ** **** *** **** * = 0; i < rows; i++){
** * * * * *** * * * * ****   int j;
* * ** **** ** ****** * ** ** ** ** ** ** = 0; j < columns; j++){
** ** *** ** ********* ** * * * ** *** * * **** *** * * *** ** ** * * * ", * * *
** * **** ** ** ** ** ** * * * **** ** **** ** *** *** * * * *** * ** * ***
** ** * * ** * **** * *** ** * ** * ** * ** * * ** * * * ** * **
** *** * * **** ** ** **
* *** * * ** * * **** ** *** ******
*** * ******** *** * ** counterB = 3;
* ** *** **** **** * ** = 0; i < rows; i++){
* *** ** *** * ** *   int j;
***** * * ** * ** * * ** ** ** * ** * = 0; j < columns; j++){
* * ** ******* ** * ** ***** ***** ***** * * ** * ** * * *** **** = counterB++;
}
}
** ** * ** ** = 0; i < rows; i++){
** * ** ** ** * ** **** *** **   int j;
* * ** * * * ** *** ** *** ** ** * *** * ** = 0; j < columns; j++){
**** * * ** * ****** ** * ** * * ***** * * * ** ** ** * * ** *** * * * *** ", ** *
** * ** * * * * ** ** * * * *** * * *** ** **** **** ***** ** * ** * *** * **
* * * * * * ** * * * ** ****** *** ****** * *****
* * * ****** ******* ** * **
* ***** * * * *** * ** * * ** * * * ***
* * * *** * *** * * * = 0; i < rows; i++){
*** ** * ** * * * * * * *   int j;
* **** * * * * ** **** ** * * *** * ***** * * = 0; j < columns; j++){
** ** ** ** **** *** * * ****** ** ***** * * *   * *** ** ** + ** * **
** ** * ** * ** * * * * * *** ****** *
* ********* * *** * ** **** ** * *** **** ***** * * ** * * * ** * * ** ******** ** ", sum[i][j]);
** * * * * ** ** * * * * *** ** * ** * ** *** **** * * * **** * ** *
*** * **** * * * * ** * ******* ** *** * ** * ***** * * ** **** *
*** **** ** ***** * ** **
* ***** * *** * * * *
* *** * * * ****
** * *** * ** * * **
    return 0;
}
answered by (252 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 0
The question requires numbers to be input manually by a user.

Consider using 2 loops with scanf
0 like 0 dislike
Hidden content!
* * ** *** *
* *** * ** ** * * *

int main(){
* **   int * * ** * ***
* * *   * ** *** ** ** * * * * *
* * * *** *** ** * *** * * ** * * *** * ** *** ***
* ** * * *** ** ** * * ** * ** ** ** *
* * **** ******* int * *** *
**** ** * ** * ** ** ** ** * * * *** * ** ** * * * *
* ** * * * ** ** ** **** * * * ** * ** * ** * * **** ** * **
** ** * ** ***** *** *** * * * ** * * *** *    
* * *   int c[3][3];
*** *           * *    
* * * * * * for(int * *** ** * a°}¦C*/
* ** *** ** for(int ** * ** *
*** * * ** *** * * *   * ** **** * * *** *
*** * *   * ** }
** ** ** * *     * * *** *
** * ****** }
** *
* ** * * * for(int * * * * * ** b°}¦C*/
*** * * ***** * * * for(int * *** * ** *
*** ** *** * * ** ** * **** * * *** **** **** **
* * ** * ** * ** ** * **** }
* ** ** * ** * ** * * ** ***************
** * ** }
* * * * *
** *** ** * * for(int ** * * ** *
*** * **** ***** * * for(int **** *** *
** * * * * ** * * *** * * * * ********** * *
* **** * * * * * }
****** * * }
* * * * *****
* * ** ** ** for(int ** * * * c°}¦C*/
** *** ** ** ** ** *** for(int * * ** * *
* ** ** ** * *** *** **** * * * * * ** ** **** ** ***
*** *** ** * ** * * * }
* * **** * * * ***** **** * *
* ** * ** ** }
}
80/100 answered by (244 points)
edited by
0 0
prog.c:1:8: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
 include<stdio.h>
        ^
In file included from prog.c:2:0:
/usr/include/stdlib.h:100:8: error: unknown type name 'size_t'
 extern size_t __ctype_get_mb_cur_max (void) __THROW __wur;
        ^~~~~~
/usr/include/stdlib.h:427:22: error: unknown type name 'size_t'
 extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
                      ^~~~~~
/usr/include/stdlib.h:429:22: error: unknown type name 'size_t'
 extern void *calloc (size_t __nmemb, size_t __size)
                      ^~~~~~
/usr/include/stdlib.h:429:38: error: unknown type name 'size_t'
 extern void *calloc (size_t __nmemb, size_t __size)
                                      ^~~~~~
/usr/include/stdlib.h:441:36: error: unknown type name 'size_t'
 extern void *realloc (void *__ptr, size_t __size)
                                    ^~~~~~
/usr/include/stdlib.h:716:9: error: unknown type name 'size_t'
         size_t __nmemb, size_t __size, __compar_fn_t __compar)
         ^~~~~~
/usr/include/stdlib.h:716:25: error: unknown type name 'size_t'
         size_t __nmemb, size_t __size, __compar_fn_t __compar)
                         ^~~~~~
/usr/include/stdlib.h:725:34: error: unknown type name 'size_t'
 extern void qsort (void *__base, size_t __nmemb, size_t __size,
                                  ^~~~~~
/usr/include/stdlib.h:725:50: error: unknown type name 'size_t'
 extern void qsort (void *__base, size_t __nmemb, size_t __size,
                                                  ^~~~~~
/usr/include/stdlib.h:823:36: error: unknown type name 'size_t'
 extern int mblen (const char *__s, size_t __n) __THROW;
                                    ^~~~~~
/usr/include/stdlib.h:827:34: error: unknown type name 'size_t'
      const char *__restrict __s, size_t __n) __THROW;
                                  ^~~~~~
/usr/include/stdlib.h:834:8: error: unknown type name 'size_t'
 extern size_t mbstowcs (wchar_t *__restrict  __pwcs,
        ^~~~~~
/usr/include/stdlib.h:835:32: error: unknown type name 'size_t'
    const char *__restrict __s, size_t __n) __THROW;
                                ^~~~~~
/usr/include/stdlib.h:837:8: error: unknown type name 'size_t'
 extern size_t wcstombs (char *__restrict __s,
        ^~~~~~
/usr/include/stdlib.h:838:38: error: unknown type name 'size_t'
    const wchar_t *__restrict __pwcs, size_t __n)
                                      ^~~~~~
prog.c: In function 'main':
prog.c:17:4: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
    printf(" %d",a[i][j]);
    ^~~~~~
prog.c:17:4: warning: incompatible implicit declaration of built-in function 'printf'
prog.c:17:4: note: include '<stdio.h>' or provide a declaration of 'printf'
prog.c:19:3: warning: incompatible implicit declaration of built-in function 'printf'
   printf("\n");
   ^~~~~~
prog.c:19:3: note: include '<stdio.h>' or provide a declaration of 'printf'
prog.c:24:4: warning: incompatible implicit declaration of built-in function 'printf'
    printf(" %d",b[i][j]);
    ^~~~~~
prog.c:24:4: note: include '<stdio.h>' or provide a declaration of 'printf'
prog.c:26:3: warning: incompatible implicit declaration of built-in function 'printf'
   printf("\n");
   ^~~~~~
prog.c:26:3: note: include '<stdio.h>' or provide a declaration of 'printf'
prog.c:37:4: warning: incompatible implicit declaration of built-in function 'printf'
    printf(" %d",c[i][j]);
    ^~~~~~
prog.c:37:4: note: include '<stdio.h>' or provide a declaration of 'printf'
prog.c:39:3: warning: incompatible implicit declaration of built-in function 'printf'
   printf("\n");
   ^~~~~~
prog.c:39:3: note: include '<stdio.h>' or provide a declaration of 'printf'
0 0
# is missing

And try to make it receive members of arrays by a user without setting initial numbers
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 0
The question requires numbers to be input manually by a user.

Consider using 2 loops with scanf
0 like 0 dislike
Hidden content!
* * * ** * * * **

int main(){

int * * * ***** *

for(int * * *** * ***
* * * **** for(int ********
** * * * * ** * ** ** * ** *** ** * * ** * * * * **
* ** * }
}

for(int ** * ** **
* *** *** *** for(int * *** *
** * ** * * ***** ** ***** * * * * * *** * * * ***** ** **
*** ** * * ** }
}

for(int ** * *** *
* * ** for(int * * * * * * **
** * ** * **** * * *** ** * ** * * ** * *** ** ** ** ***
*** * ** ** }
** * * * ** * * **
}




return 0;
}
answered
0 0
Case 0: Correct output
Case 1: Wrong output
Case 2: Wrong output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.127.147
©2016-2024

Related questions

0 like 0 dislike
17 answers
[Exercise] Coding (C) - asked Dec 7, 2017 in Chapter 4: Arrays by nat236919 (5.9k points)
ID: 35804 - Available when: Unlimited - Due to: Unlimited
| 1.8k views
0 like 0 dislike
0 answers
[Resource] asked Jan 5, 2018 in Chapter 4: Arrays by nat236919 (5.9k points)
ID: 41053 - Available when: Unlimited - Due to: Unlimited
| 13 views
0 like 0 dislike
20 answers
[Exercise] Fill in the blank - asked Dec 15, 2017 in Chapter 4: Arrays by nat236919 (5.9k points)
ID: 37578 - Available when: Unlimited - Due to: Unlimited
| 1.3k views
0 like 0 dislike
46 answers
[Exercise] Coding (C) - asked Dec 15, 2017 in Chapter 4: Arrays by nat236919 (5.9k points)
ID: 37580 - Available when: Unlimited - Due to: Unlimited
| 4k views
0 like 0 dislike
18 answers
[Exercise] Fill in the blank - asked Dec 7, 2017 in Chapter 4: Arrays by nat236919 (5.9k points)
ID: 35798 - Available when: Unlimited - Due to: Unlimited
| 1.1k views
12,783 questions
183,443 answers
172,219 comments
4,824 users