Jump to content

Problema Informatica: Matrice Cu 10 Linii Si 7 Coloane


Go to solution Solved by Courage,

Recommended Posts

Posted

Se da urmatoarea problema:Scrieţi un program C/C++ care construieşte în memorie o matrice cu 10 linii şi 7 coloane ale cărei elemente sunt numere întregi (cu maximum 3 cifre fiecare), citite de la tastatură, şi afişează pe ecran, suma tuturor elementelor situate pe conturul matricei determinat de prima şi ultima linie respectiv prima şi ultima coloană a acestei matrice.
 

 

Asa am incercat eu sa o fac:

#include<iostream>
using namespace std;
int suma (int suma);
int main()
{
    int a[10][7],l=10,c=7,i,j,s=0;
    for(i=1;i<=l;i++)
for(j=1;j<=c;j++)
{
    cout<<"a["<<i<<"]["<<j<<"]=";
    cin>>a[i][j];}
    s=suma(a[i][j]);
    cout<<"Suma este"<<s;
    return 0;
}
int suma (int suma)
{
    int a[10][7],n, i,j;
    for (i=1; i<=10; i++)
        n=n+a[i][1];
    for (i=1;i i<=10; i++)
        n=n+a[i][7];
    for (j=1; j<=7; j++)
        n=n+a[1][j];
    for (j=1; j<=7; j++)
        n=n+a[10][j];
    return n;
}


  • Moderators
Posted

Nu l-am testat...

#include <iostream>

using namespace std;

int main (void)
{
    int a[10][10], n, i, j;
    for (i=1 ; i <= 10 ; i++)
    {
        for (j=1 ; j <= 7 ; j++)
        {
            cout << "a[" << i << "][" << j << "]=";
            cin >> a[i][j];
        }
    }
    int s = 0;
    for (j=1 ; j <= 7 ; j++)
        s += a[1][j] + a[10][j];
    for (i=2 ; i < 10 ; i++)
        s+= a[i][1] + a[i][7];
    cout << s;
    return 0;
}

  • Moderators
  • Solution
Posted
#include <iostream>

using namespace std;

int main (void)
{
    int a[15][15], n, i, j;
    for (i=1 ; i <= 10 ; i++)
    {
        for (j=1 ; j <= 7 ; j++)
        {
            cout << "a[" << i << "][" << j << "]=";
            cin >> a[i][j];
        }
    }
    int s = 0;
    for (j=1 ; j <= 7 ; j++)
        s += a[1][j] + a[10][j];
    for (i=2 ; i < 10 ; i++)
        s+= a[i][1] + a[i][7];
    cout << s;
    return 0;
}

  • Upvote 1
  • Moderators
Posted

Mie-mi afiseaza 30 daca iau toate elementele 1, ceea ce trebuie :)

#include <iostream>

using namespace std;

int main (void)
{
    int a[15][15], n, i, j;

    for (i=1 ; i <= 10 ; i++)
    {
        
        for (j=1 ; j <= 7 ; j++)
            a[i][j] = 1;
            
    }
    
    /*
    for (i=1 ; i <= 10 ; i++)
    {
        for (j=1 ; j <= 7 ; j++)
        {
            cout << "a[" << i << "][" << j << "]=";
            cin >> a[i][j];
        }
    }*/
    
    int s = 0;
    
    for (j=1 ; j <= 7 ; j++)
        s += a[1][j] + a[10][j];
    for (i=2 ; i < 10 ; i++)
        s+= a[i][1] + a[i][7];
        
    cout << s;
    
    return 0;
}

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.