Skip to content

Instantly share code, notes, and snippets.

@Tamkien
Created June 29, 2021 16:53
Show Gist options
  • Save Tamkien/3118bc17740dccea22e7bcab736cbf79 to your computer and use it in GitHub Desktop.
Save Tamkien/3118bc17740dccea22e7bcab736cbf79 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main()
{
int n,m,i,j;
float a[10][10];
printf("Nhap so hang ma tran");
scanf("%d", &m);
printf("Nhap so cot ma tran");
scanf("%d", &n);
printf("\nNhap tung phan tu\n");
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
printf("a[%d][%d]=", i, j);
scanf("%f", &a[i][j]);
}
}
// Neu co cai // thi la chu thich thoi, k chep nhe.
//Cau 2
//chep nguyen 2 cai for cua de bai, sua printf va xoa scanf
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
//cai printf co them mot cai %f voi a[i][j] nua, chinh la gia tri cua tung phan tu.
//%f vi kieu du lieu cua phan tu la float
printf("a[%d][%d]= %f\n", i, j, a[i][j]);
}
}
//Cau 3
//De yc in gtri cua hang cuoi cung, nen minh se for tu 0 den het so cot
float sum = 0; //cai sum nay de tinh tong, float la kieu du lieu
for (i = 0; i < n; i++) {
//m-1 la index cua hang cuoi cung. += de cong them vao cai sum.
sum += a[m-1][i];
}
//in ra cai sum
printf("%f", sum);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment