Advertisement
Guest User

26

a guest
Jan 18th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. int a[50][50], n, m;
  6.  
  7. bool prim(int nr) {
  8.     for(int i=2; i<=nr/2; i++)
  9.         if(nr%i==0)
  10.             return false;
  11.     return true;
  12. }
  13.  
  14. int main() {
  15.     ifstream fin("in.txt");
  16.     ofstream fout("out.txt");
  17.     fin>>n>>m;
  18.     for(int i=0; i<n; i++)
  19.         for(int j=0; j<m; j++)
  20.             fin>>a[i][j];
  21.  
  22.     for(int i=0; i<n; i++) {
  23.         int suma=0, nrN=0;;
  24.         for(int j=0; j<m; j++) {
  25.             fout<<a[i][j]<<" ";
  26.             if(prim(a[i][j])) {
  27.                 ++nrN;
  28.                 suma+=a[i][j];
  29.             }
  30.         }
  31.         fout<<"  Linia "<<i<<" - ";
  32.         if(nrN==0)
  33.             fout<<"fara elemente prime";
  34.         else
  35.             fout<<(float)suma/nrN;
  36.         fout<<'\n';
  37.     }
  38.  
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement