Advertisement
Guest User

ONLY MINIPERACI CLICK HERE :)

a guest
Feb 19th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #define RADKY 8
  5. #define SLOUPCE 10
  6.  
  7. void naplnPole(int pole[RADKY][SLOUPCE]){
  8. int r,s;
  9. for(r=0;r<RADKY;r++){
  10. for(s=0;s<RADKY;s++){
  11. pole[r][s]=rand()%99+1;
  12. }
  13. }
  14. return;
  15. }
  16.  
  17. void vypisPole(int pole[RADKY][SLOUPCE]){
  18. int r,s;
  19. for(r=0;r<RADKY;r++){
  20. for(s=0;s<RADKY;s++){
  21. printf("%3d",pole[r][s]);
  22. }
  23. printf("\n");
  24. }
  25. return;
  26. }
  27.  
  28. void bubbleSort(int pole[RADKY][SLOUPCE]){
  29. int r,s,x,pom;
  30. for(s=0;s<SLOUPCE;s++){
  31. for(x=RADKY;x>1;x--){
  32. for(r=0;r<x-1;r++){
  33. if(pole[r][s]>pole[r+1][s]){
  34. pom=pole[r][s];
  35. pole[r][s]=pole[r+1][s];
  36. pole[r+1][s]=pom;
  37. }
  38. }
  39. }
  40. }
  41. return;
  42. }
  43.  
  44. int main(int argc, char** argv) {
  45. int matice[RADKY][SLOUPCE];
  46. int r,s;
  47. srand((unsigned)time(NULL));
  48.  
  49. FILE*pFile;
  50. pFile=fopen("vystup.txt","w");
  51. naplnPole(matice);
  52. vypisPole(matice);
  53. bubbleSort(matice);
  54. printf("\n");
  55. vypisPole(matice);
  56.  
  57. if(pFile!=NULL){
  58. for(r=0;r<RADKY;r++){
  59. for(s=0;s<RADKY;s++){
  60. fprintf(pFile,"%3d",matice[r][s]);
  61. }
  62. fprintf(pFile,"\n");
  63. }
  64. fclose(pFile);
  65. }
  66.  
  67. return (EXIT_SUCCESS);
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement