Tuesday, August 12, 2014

Câu 2.19: Viết chương trình nhập vào một mảng hai chiều amxn gồm các số nguyên. Tính và in ra màn hình tổng của các phần tử trên mỗi cột.

//code Dung NV
#include <stdio.h>
#include <conio.h>
void nhap(int a[][50],int x,int y)
{
    int i,j;
    for (i=0;i<x;i++)
    for (j=0;j<y;j++)
    {
        printf("nhap phan tu [%d][%d] : ",i,j);
        scanf("%d",&a[i][j]);
    }
}
void xuat(int a[][50],int x,int y)
{
    int i,j;
    for (i=0;i<x;i++)
    {
       for (j=0;j<y;j++)
       printf(" %d ",a[i][j]);
       printf("\n");
    }
}
void tongcot(int a[][50],int x,int y)
{
                int i,j,tc;
    for (i=0;i<y;i++)
    {
       tc=0;
       for (j=0;j<x;j++)
                tc+=a[j][i];
       printf("\nTong cot thu %d :   %5d",i,tc);        
    }
}
void main()
{
    int m,n;
    int a[50][50];
    printf("nhap so hang ,so cot");
    scanf("%d%d",&m,&n);
    printf("nhap mang : \n");
    nhap(a,m,n);
    printf("\n in mang  \n");
    xuat(a,m,n);
    tongcot(a,m,n);
    getch();

}

No comments:

Post a Comment