void funint array44int j; forj=0;j4;j++ printf-2darray2j; printfnvoid mainvoidint a44=0120100420050450; funa;
There are a few errors in this code:
- The function
funis missing a semicolon at the end of its declaration. - The
printfstatement infunis using the incorrect escape character for a new line. It should be\ninstead of/n. - In the
printfstatement infun, the format specifier%-2dis used, which will print the integer with a minimum width of 2 characters and left-align it. However, since all the integers in the array are single-digit, this format specifier is unnecessary and can be simplified to%d. - In the
mainfunction, the return type should beintinstead ofvoid. - The
mainfunction is missing a return statement at the end.
Here is the corrected code:
#include <stdio.h>
void fun(int array[4][4]) {
int j;
for (j = 0; j < 4; j++) {
printf("%d ", array[2][j]);
}
printf("\n");
}
int main(void) {
int a[4][4] = {{0,1,2,0},{1,0,0,4},{2,0,0,5},{0,4,5,0}};
fun(a);
return 0;
}
This code will print out the numbers in the third row of the a array separated by spaces and followed by a new line:
2 0 0 5
``
原文地址: https://www.cveoy.top/t/topic/fcDa 著作权归作者所有。请勿转载和采集!