Advertisement
Guest User

Marcinek2

a guest
Oct 21st, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cstdlib>
  4. #include <ctime>
  5. #include <string>
  6. using namespace std;
  7. int rozmiar()
  8. {
  9. int rozmiar;
  10. cout<<"Podaj rozmiar tablicy:"<<endl;
  11. cin>>rozmiar;
  12. while(rozmiar<5||rozmiar>15||rozmiar==0)
  13. {
  14. cout<<"Podaj rozmiar tablicy"<<endl;
  15. cin>>rozmiar;
  16.  
  17. }
  18. return rozmiar;
  19. }
  20. void losowanie(int n,int t[][15])
  21. {
  22. srand(time(NULL));
  23. for(int i=0;i<n;i++)
  24. {
  25. for(int j=0;j<15;j++)
  26. {
  27.  
  28. t[i][j]=rand()%201-100;
  29. }
  30. }
  31.  
  32. }
  33. int wyswietlanie(int n, int t[][15])
  34. {
  35. for(int i=0;i<n;i++)
  36. {
  37. for(int j=0;j<15;j++)
  38. {
  39. cout << t[i][j] << " ";
  40. }
  41. cout << endl;
  42. }
  43. }
  44. void dzialania(int n, int t[][15])
  45. {
  46. int iloscplus=0,ilosczer=0,suma=0,srednia=0;
  47. for(int i=0;i<n;i++)
  48. {
  49. for(int j=0;j<15;j++)
  50. {
  51. if(t[i][j]>0)
  52. {
  53. iloscplus +=1;
  54. }
  55. if(t[i][j]==0)
  56. {
  57. ilosczer +=1;
  58. }
  59. suma +=t[i][j];
  60. }
  61. }
  62. srednia += suma/(n+1) *16;
  63. cout<<"Ilosc elementow wiekszych od 0:"<<iloscplus<<endl;
  64. cout<<"Ilosc zer:"<<ilosczer<<endl;
  65. cout<<"suma:"<<suma<<endl;
  66. cout<<"srednia:"<<srednia<<endl;
  67. }
  68. int main()
  69. {
  70. int n=rozmiar();
  71. int t[n][15];
  72. losowanie(n,t);
  73. wyswietlanie(n,t);
  74. dzialania(n,t);
  75. return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement