suma elemente pe linie

Se da o matrice cu m lini * n coloane.Sa se memoreze intr-un vector b sumele elementelor de pe fiecare lini a matricii ( b[i] va reprezenta suma elementelor de pe linia i in matrice)

#include<iostream.h>
int a[20][20],b[30],i,j,n,m;
void main()
{
cout<<“n=”;cin>>n;
cout<<“m=”;cin>>m;
for(i=0;i<=m-1;i++)
for(j=0;j<=n-1;j++)
{
cout<<“a[“<<i<<“][“<<j<<“]=”;
cin>>a[i][j];
}
for(i=0;i<=m-1;i++)
b[i]=0;
for(i=0;i<=m-1;i++)
for(j=0;j<=n-1;j++)
b[i]=b[i]+a[i][j];
for(i=0;i<=m-1;i++)
cout<<b[i]<<” “;
}

{joscommentenable}

Facebook Comments