01/10/2018, 16:46
Viết hàm tính tổng chéo chính ma trận
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include "stdio.h"
#include "conio.h"
#define max 100
void nhapmang(int , int , int &)
void xuatmang(int , int , int )
int tongcheo(int , int , int )
void nhapmang(int a[max][max],int hang,int cot )
{
for (int i = 1; i <= hang; i++)
{
for (int j = 1; j <= cot; j++)
{
printf("a[%d][%d]=", i, j);
scanf("%d", &a[i][j]);
}
}
}
void xuatmang(int a[max][max],int hang,int cot)
{
for (int i = 1; i <= hang; i++)
{
for (int j = 1; j <= cot; j++)
{
printf("%d ", a[i][j]);
}
printf("
");
}
}
int tongcheo(int a[max][max], int hang, int cot )
{
int tong = 0;
for (int i = 1; i <= hang; i++)
{
for (int j = 1; j <= cot; j++)
{
if (i == j)
{
tong =tong + a[i][j];
}
}
}
return tong;
}
int main()
{
int a[max][max];
int cot, hang;
printf("nhap hang:");
scanf("%d", &hang);
printf("nhap cot:");
scanf("%d", &cot);
nhapmang(a,hang,cot);
xuatmang(a,hang,cot);
int kq = tongcheo(a, hang, cot);
printf("kq la %d", kq);
return 0;
}
bị lỗi :
Error C2144 syntax error: ‘void’ should be preceded by ‘;’
Error C2144 syntax error: ‘int’ should be preceded by ‘;’
em sửa qài vẫn không được mọi người giúp em với
Bài liên quan
Dấu chấm phẩy(
dạ em cảm ơn a ạ !! em bất cẩn qá