Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define RADKY 8
- #define SLOUPCE 10
- void naplnPole(int pole[RADKY][SLOUPCE]){
- int r,s;
- for(r=0;r<RADKY;r++){
- for(s=0;s<RADKY;s++){
- pole[r][s]=rand()%99+1;
- }
- }
- return;
- }
- void vypisPole(int pole[RADKY][SLOUPCE]){
- int r,s;
- for(r=0;r<RADKY;r++){
- for(s=0;s<RADKY;s++){
- printf("%3d",pole[r][s]);
- }
- printf("\n");
- }
- return;
- }
- void bubbleSort(int pole[RADKY][SLOUPCE]){
- int r,s,x,pom;
- for(s=0;s<SLOUPCE;s++){
- for(x=RADKY;x>1;x--){
- for(r=0;r<x-1;r++){
- if(pole[r][s]>pole[r+1][s]){
- pom=pole[r][s];
- pole[r][s]=pole[r+1][s];
- pole[r+1][s]=pom;
- }
- }
- }
- }
- return;
- }
- int main(int argc, char** argv) {
- int matice[RADKY][SLOUPCE];
- int r,s;
- srand((unsigned)time(NULL));
- FILE*pFile;
- pFile=fopen("vystup.txt","w");
- naplnPole(matice);
- vypisPole(matice);
- bubbleSort(matice);
- printf("\n");
- vypisPole(matice);
- if(pFile!=NULL){
- for(r=0;r<RADKY;r++){
- for(s=0;s<RADKY;s++){
- fprintf(pFile,"%3d",matice[r][s]);
- }
- fprintf(pFile,"\n");
- }
- fclose(pFile);
- }
- return (EXIT_SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement