Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<time.h>
  4.  
  5.  
  6. //Zadanie dla Weroniki Kołodziej
  7. //Henryk Nowakowski
  8.  
  9. int main( void )
  10. {
  11. int matrix[9][9], matrix2[9][9];
  12. int sum;
  13. int current_row; // żeby wiedzieć od które momentu dodawać w+k(wiersz + kolumna)
  14. int current_col; //
  15.  
  16. srandom( (unsigned) time(NULL) );
  17.  
  18. //W każdej komórce losowe [1, 5]
  19. //jak suma komórek > 25 resztę wypełni nr kolumny+wiersza
  20.  
  21.  
  22. for (int i = 0; i < 9; i++) {
  23. for(int j = 0; j < 9; j++)
  24. {
  25. matrix[i][j]=random()%5;
  26. sum += matrix[i][j]; //sumowanie wylosowanych liczb
  27. if(sum >= 25){
  28. current_row = i; //zapisanie miejsca, w którym zmienna sum wynosiła już 25 lub więcej
  29. current_col = j;
  30. break;
  31. }
  32. }
  33. if(sum >= 25)
  34. break;
  35. }
  36. printf("\n\nMiejce, w ktorym zsumowane komórki >= 25 to wiersz %d i kolumna %d\n\n", current_row, current_col);
  37.  
  38.  
  39.  
  40. /*
  41. 1. Niżej przedstawione pętle nie mają zdeklarowanej zmiennej, bo zostało to już
  42. zrobione
  43.  
  44. 2. Po wykonaniu pętli, current_col zostaje wyzerowana, żeby mogła się wykonać
  45. dla kolejnych wierszy
  46. */
  47. if(sum >= 25)
  48. {
  49. for( ;current_row < 9;current_row++) {
  50. for( ;current_col < 9; current_col++)
  51. {
  52. matrix[current_row][current_col] = current_row+current_col;
  53. }
  54. current_col=0;
  55. }
  56. }
  57.  
  58.  
  59.  
  60. //WYPISYWANIE TABLICY OK -----------------
  61.  
  62.  
  63. for (int i = 0; i < 9; i++) {
  64. for(int j = 0; j<9; j++)
  65. {
  66. printf("%d, ", matrix[i][j]);
  67.  
  68. }
  69. printf("\n");
  70. }
  71.  
  72.  
  73. //----------------------------------------
  74. return ( 0 ) ;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement