Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <ctime>
  4. const int N=5;
  5. struct Dane{
  6. char litera;
  7. double liczba;
  8.  
  9. };
  10.  
  11. using namespace std;
  12.  
  13. int main()
  14. {
  15. srand(time(0));
  16. double A=-20,b=20;
  17.  
  18. Dane a[N][N];
  19. for (int i=0;i<N;i++){
  20. for (int j=0;j<N;j++){
  21. a[i][j].liczba=A+(b-A)*rand()/double (RAND_MAX);
  22. a[i][j].litera='A'+rand()%('Z'+1-'A');
  23. cout<<fixed<<setprecision(2)<<setw(4)<<a[i][j].liczba<<a[i][j].litera<<'\t';
  24. }
  25. cout<<endl;
  26.  
  27. }
  28. cout<<endl;
  29. cout<<endl;
  30. cout<<endl;
  31.  
  32. double max1=a[1][0].liczba;
  33. int imax1=1;
  34. int jmax1=0;
  35. for (int i=1;i<N;i++){
  36. for (int j=0;j<i-1;j++){
  37. if (a[i][j].liczba>max1){
  38. max1=a[i][j].liczba;
  39. imax1=i;
  40. jmax1=j;
  41.  
  42. }
  43. }
  44. }
  45. cout<<"maksymalna liczba pod glowna przekatna:";
  46. cout<<max1<<endl;
  47. cout<<endl;
  48. cout<<endl;
  49.  
  50. double max2=a[0][N-1].liczba;
  51. int imax2=0;
  52. int jmax2=N-1;
  53. for (int i=0;i<N;i++){
  54. for (int j=N-3;j<N;j++){
  55. if (a[i][j].liczba>max2){
  56. max2=a[i][j].liczba;
  57. imax2=i;
  58. jmax2=j;
  59. }
  60. }
  61. }
  62. cout<<"maksymalna liczba z 3 ostatnich kolumn: ";
  63. cout<<max2;
  64. cout<<endl;
  65.  
  66. if (max1>max2 || max1==max2){
  67. cout<<"wieksza liczba: ";
  68. cout<<max1;
  69. }
  70. else
  71. cout<<"wieksza liczba: "<<max2;
  72. cout<<endl;
  73.  
  74. return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement