Video appunto: Sommare elementi di una matrice un valore "x"
C++ - Sommare agli elementi di una matrice un valore "x"
// Sommare agli elementi della matrice un valore "x"
#include
using namespace std;
// ----- VARIABILI GLOBALI ----- //
const int massimo=100;
// ----- /VARIABILI GLOBALI ----- //
// ----- PROTOTIPI ----- //
int dimensione_righe();
int dimensione_colonne();
void caricamento_matrice(float [massimo][massimo], int, int);
void stampa_matrice(float [massimo][massimo], int, int);
void somma_elementi(float [massimo][massimo], int, int);
// ----- /PROTOTIPI ----- //
// ----- FUNZIONI ----- //
int dimensione_righe()
{
int nr;
cout cin>>nr;
while (nr>massimo)
{
cout cin>>nr;
}
return nr;
}
int dimensione_colonne()
{
int nc;
cout cin>>nc;
while (nc>massimo)
{
cout cin>>nc;
}
return nc;
}
void caricamento_matrice(float m[massimo][massimo], int nr, int nc)
{
for (int i=0; i
for (int j=0; j
cout cin>>m[j];
}
}
}
void stampa_matrice(float m[massimo][massimo], int nr, int nc)
{
for (int i=0; i
for (int j=0; j
cout[j] }
cout }
}
void somma_elementi(float m[massimo][massimo], int nr, int nc)
{
int x;
cout cin>>x;
cout for (int i=0; i
for (int j=0; j
m[j]=m[j]+x;
}
}
}
// ----- /FUNZIONI ----- //
// ----- PROGRAMMA PRINCIPALE ----- //
int main()
{
float matrice[massimo][massimo];
int righe=dimensione_righe();
cout int colonne=dimensione_colonne();
cout caricamento_matrice(matrice, righe, colonne);
cout stampa_matrice(matrice, righe, colonne);
somma_elementi(matrice, righe, colonne);
cout stampa_matrice(matrice, righe, colonne);
return 0;
}
// ----- /PROGRAMMA PRINCIPALE ----- //