Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Câu hỏi 1

Chính xác

Điểm 1,00 của 1,00

Cho một ma trận gồm n hàng và n cột, các phần tử đều là số nguyên, với n và các phần tử được nhập từ bàn phím (n <= 10). Viết chương
trình tính tổng các phần tử biên tại các vị trí biên của ma trận đó.

For example:

Test Input Result

Test case 1 3 40
1 2 3
4 5 6
7 8 9

Answer: (penalty regime: 10, 20, ... %)


1 #include<stdio.h>
2 ▼ void Nhap(int a[][100], int n){
3 ▼ for(int i =0; i< n; i++){
4 ▼ for(int j =0 ; j<n; j++){
5 scanf("%d", &a[i][j]);
6 }
7 }
8 }
9 int Sum(int a[100][100], int n)
10 ▼ {
11 int sum = 0;
12 for(int i = 0; i < n; i++)
13 ▼ {
14 sum += a[i][0];
15 sum += a[i][n-1];
16 }
17 for(int j = 0; j < n; j++)
18 ▼ {
19 sum += a[0][j];
20 sum += a[n-1][j];
21 }
22 sum -= a[0][0];
23 sum -= a[n-1][n-1];
24 [0][ 1]

Test Input Expected Got

 Test case 1 3 40 40 
1 2 3
4 5 6
7 8 9

 Test case 2 4 61 61 
1 2 3 3
4 5 6 6
7 8 9 9
7 2 9 8

 Test case 3 2 10 10 
1 2
3 4

 Test case 4 3 -21 -21 


-2 -4 -6
-8 -10 -12
1 3 7
Test Input Expected Got

 Test case 5 5 54 54 
3 3 3 3 3
6 6 6 6 6
9 9 9 9 9
2 2 2 2 2
1 1 1 1 1

Passed all tests! 

Chính xác

Điểm cho bài nộp này: 1,00/1,00.


Câu hỏi 2

Chính xác

Điểm 1,00 của 1,00

Cho một ma trận gồm n hàng và n cột, các phần tử là các số nguyên, với n và các phần tử được nhập từ bàn phím (n <= 20). Xác định có bao
nhiêu số chia hết cho 3 trong ma trận đó.

For example:

Test Input Result

Test case 1 2 1
1 3
2 4

Answer: (penalty regime: 10, 20, ... %)


1 #include<stdio.h>
2 ▼ void Nhap(int a[][100], int n){
3 ▼ for(int i =0; i< n; i++){
4 ▼ for(int j =0 ; j<n; j++){
5 scanf("%d", &a[i][j]);
6 }
7 }
8 }
9 int Sochiahetcho3(int a[100][100], int n)
10 ▼ {
11 int x = 0;
12 ▼ for(int i = 0; i < n; i++){
13 ▼ for(int j = 0; j < n; j++){
14 if( a[i][j] % 3 == 0)
15 x++;
16 }
17 }
18 printf("%d", x);
19 return 0;
20 }
21 ▼ int main(){
22 int a[100][100];
23 int n;
24 f("%d" & )

Test Input Expected Got

 Test case 1 2 1 1 
1 3
2 4

 Test case 2 3 3 3 
1 2 3
6 5 4
8 7 9

 Test case 3 4 5 5 
1 3 5 7
9 11 13 15
2 4 6 8
1 3 5 7

 Test case 4 3 3 3 
-2 -4 -6
-8 -10 -12
1 3 7

 Test case 5 5 20 20 
3 3 3 3 3
6 6 6 6 6
9 9 9 9 9
2 2 2 2 2
0 0 0 0 0
Passed all tests! 

Chính xác

Điểm cho bài nộp này: 1,00/1,00.


Câu hỏi 3

Chính xác

Điểm 1,00 của 1,00

Viết một hàm xuất các phần tử của mảng hai chiều (nxm) ra màn hình không có khoảng trắng hay dấu xuống dòng ở cuối,
giữa các phần tử chỉ có đúng 1 khoảng trắng.

Input: Mảng hai chiều, kích thước hàng, kích thước cột
Output: các phần tử của mảng

For example:

Test Result

int row = 3; 1 2 3
int col = 3; 4 5 6
int matrix[100][100] = {{1,2,3}, 7 8 9
{4,5,6},
{7,8,9}};
PrintMatrix(matrix, row, col)

Answer: (penalty regime: 10, 20, ... %)

Reset answer

1 ▼ void PrintMatrix(int matrix[100][100], int row, int col){


2
3 scanf("%d",&row);
4 scanf("%d",&col);
5 ▼ for(int i = 0; i < row; i++){
6 ▼ for(int j =0 ; j<col; j++){
7 scanf("%d",&matrix[i][j]);
8 }
9 }
10 ▼ for(int i =0; i< row; i++){
11 ▼ for(int j =0 ; j<col; j++){
12 printf("%d ", matrix[i][j]);
13 }
14 printf("\n");
15 }
16
17 }

Test Expected Got

 int row = 3; 1 2 3 1 2 3 
int col = 3; 4 5 6 4 5 6
int matrix[100][100] = {{1,2,3}, 7 8 9 7 8 9
{4,5,6},
{7,8,9}};
PrintMatrix(matrix, row, col)

 int row = 2; 2 3 2 3 
int col = 2; 5 6 5 6
int matrix[100][100] = {{2,3},
{5,6}};
PrintMatrix(matrix, row, col)
Test Expected Got

 int row = 3; 1 2 3 10 1 2 3 10 
int col = 4; 4 5 6 11 4 5 6 11
int matrix[100][100] = {{1,2,3,10}, 7 8 9 12 7 8 9 12
{4,5,6,11},
{7,8,9,12}};
PrintMatrix(matrix, row, col)

 int row = 4; 1 2 3 10 1 2 3 10 
int col = 4; 4 5 6 11 4 5 6 11
int matrix[100][100] = {{1,2,3,10}, 7 8 9 12 7 8 9 12
{4,5,6,11}, 13 14 15 12 13 14 15 12
{7,8,9,12},
{13,14,15,12}};
PrintMatrix(matrix, row, col)

Passed all tests! 

Chính xác

Điểm cho bài nộp này: 1,00/1,00.


Câu hỏi 4

Chính xác

Điểm 1,00 của 1,00

Viết một hàm tính tổng các phần tử trong ma trận (nxm) kiểu số thực và trả về giá trị đó.

int sumMatrix(int M[100][100], int rows, int cols)

Input: Ma trận, kích thước hàng, kích thước cột


Output: Tổng các phần tử

For example:

Test Result

int row = 3; 45.000


int col = 3;
float matrix[100][100] = {{1,2,3},
{4,5,6},
{7,8,9}};
printf("%.3f",SumMatrix(matrix,row,col));

Answer: (penalty regime: 10, 20, ... %)

Reset answer

1 float SumMatrix(float M[100][100], int rows, int cols)


2 ▼ {
3 scanf("%d", &rows);
4 scanf("%d", &cols);
5 ▼ for(int i =0; i< rows; i++){
6 ▼ for(int j =0 ; j<cols; j++){
7 scanf("%f", &M[i][j]);
8 }
9 }
10 double sum = 0;
11 ▼ for(int i = 0; i < rows; i++){
12 ▼ for(int j = 0; j < cols; j++){
13 sum += M[i][j];
14
15 }
16 }
17 return sum;
18 }

Test Expected Got

 int row = 3; 45.000 45.000 


int col = 3;
float matrix[100][100] = {{1,2,3},
{4,5,6},
{7,8,9}};
printf("%.3f",SumMatrix(matrix,row,col));

 int row = 3; 16.000 16.000 


int col = 3;
float matrix[100][100] = {{1.4,2,3},
{4,-5.5,6},
{7,8,-9.9}};
printf("%.3f",SumMatrix(matrix,row,col));
Test Expected Got

 int row = 1; 6.400 6.400 


int col = 3;
float matrix[100][100] = {{1.4,2,3}};
printf("%.3f",SumMatrix(matrix,row,col));

 int row = 2; 10.900 10.900 


int col = 3;
float matrix[100][100] = {{1.4,2,3},
{4,-5.5,6}};
printf("%.3f",SumMatrix(matrix,row,col));

Passed all tests! 

Chính xác

Điểm cho bài nộp này: 1,00/1,00.


Câu hỏi 5

Chính xác

Điểm 1,00 của 1,00

Hiện thực hàm tính tổng các dòng lẻ của matrix

For example:

Test Result

int M[100][100] = {{1,2},{-2,0}}; -2


printf("%d", SumOddRowsMatrix(M,2,2));

Answer: (penalty regime: 10, 20, ... %)


1 ▼ int SumOddRowsMatrix( int M[100][100], int m, int n){
2 scanf("%d", &m);
3 scanf("%d", &n);
4 ▼ for(int i =0; i< m; i++){
5 ▼ for(int j =0 ; j<n; j++){
6 scanf("%d", &M[i][j]);
7 }
8 }
9 int sum =0 ;
10 ▼ for(int i = 0; i < m ; i++){
11 ▼ for(int j = 0; j < n ; j++){
12 if(i%2!=0)
13 sum += M[i][j];
14 }
15 }
16 return sum;
17
18 }

Test Expected Got

 int M[100][100] = {{1,2},{-2,0}}; -2 -2 


printf("%d", SumOddRowsMatrix(M,2,2));

 int M[100][100] = {{1,2,3},{-2,0,-5},{10,3,-8}}; -7 -7 


printf("%d", SumOddRowsMatrix(M,3,3));

 int M[100][100] = {{1,2},{-2,0},{-8,-3}}; -2 -2 


printf("%d", SumOddRowsMatrix(M,3,2));

 int M[100][100] = {{1,2},{-2,0},{-5,9},{12,-7}}; 3 3 


printf("%d", SumOddRowsMatrix(M,4,2));

 int M[100][100] = {{1,2,3,4,5},{-2,10,-2,-9,-3},{0,9,8,7,6},{4,3,5,3,1},{-3,-9,-6,4,4}}; 10 10 


printf("%d", SumOddRowsMatrix(M,5,5));

Passed all tests! 

Chính xác

Điểm cho bài nộp này: 1,00/1,00.

◄ Lab3.2 DT03 TUS

Chuyển tới...

Lab3.4 DT03 TUS ►

You might also like