Khai báo một mảng 2 chiều có kích thước (5x5), thực hiện nhập và tính tổng giá trị từng hàng và tổng giá trị của các phần tử theo đường chéo và đưa ra kết quả.
code em đành là như thế này
// nhap.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "conio.h"
#include "iostream.h"
#include "stdio.h"
#include "math.h"
void main(int argc, char* argv[])
{
//int n=5;//cot
//int m=5;//hang
int Mang[5][5];
int sophantu;
sophantu = 5*5;
int Mang1chieu[100];
for(int i=0;i<6;i++)
{
for(int j=0;j<6;j++)
{
printf("Mang[%d][%d]=",i,j);
cin>> Mang[i][j];
printf("\n");
}
}
//thuc hien sap xep mang
int dem ;
dem=0;
for(int i1=0;i1<6;i1++)
{
for(int j1=0;j1<6;j1++)
{
Mang1chieu[dem]=Mang[i1][j1];
dem++;
}
}
printf("So phan tu trong mang 1 chieu!\n");
for(int i2=0;i2<sophantu;i2++)
{
printf("%d\t",Mang1chieu[i2]);
}
void tongpttrendong(int a[][100])
{
for(int i=0;i<6;++i)
{
int S=0;
for(int j=0;j<6;++j)
S+=a[i][j];
cout<<"dong "<<i<<" la: "<<S<<endl;
}
}
int tongptdcchinh(int a[][100])
{
int t=0;
for(int i=0;i<n;i++)
t=t+a[i][i];
return t;
}
getch();
}