Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Recapitulare pentru teza
- 2. Se citeste n din fisierul numere.txt, iar apoi n^2 numere naturale ce se vor citi din acelasi fisier.
- Sa se calculeze
- a) suma celor din triunghiul de sus
- b) media aritmetica din triunghiul de jos
- c) numerele pare din triunghiul din stanga
- d) produsul numerelor din dreapta
- */
- #include <fstream>
- using namespace std;
- int main()
- {
- int n, i, j, a[100][100], S(0), P(1), nrPare(0), contor(0), Smedie(0);
- ifstream fin("numere.txt");
- fin >> n;
- for(i = 1; i <= n; i++) {
- for(j = 1; j <= n; j++)
- fin >> a[i][j];
- }
- fin.close();
- ofstream fout("output.txt");
- for(i = 1; i <= n; i++) {
- for(j = 1; j <= n; j++)
- {
- if(i < j && i + j < n + 1)
- S += a[i][j];
- else
- if(i < j && i + j > n + 1)
- P *= a[i][j];
- else
- if(i > j && i + j > n + 1)
- {
- contor++;
- Smedie += a[i][j];
- }
- else
- if(i > j && i + j < n + 1)
- if(a[i][j] % 2 == 0)
- nrPare++;
- }
- }
- fout << "Suma: " << S << endl;
- fout << "Produsul: " << P << endl;
- fout << "Media aritmetica: " << (float)Smedie / contor << endl;
- fout << "Numere pare: " << nrPare;
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment