Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. #define N 10
  6. #define M 15
  7.  
  8. int main()
  9. {
  10.    
  11.     int pin1[N], pin2[M];
  12.     int j, i, k, num, potition, temp, check;
  13.    
  14.    
  15.    
  16.         // 1ST MATRIX
  17.     printf("INITIAL MATRIX\n");
  18.    
  19.     // edw gemizeis ton pinaka enw soy leei na mhn to kaneis
  20.     /*
  21.     for(i=0;i<N;i++){
  22.         pin1[i] = rand()%10;                specific seed to test matrix
  23.     }
  24.      for(i=0;i<N;i++){
  25.        
  26.         printf("Potition: %d: %d\n", i, pin1[i]);
  27.     }
  28.     */
  29.  
  30.    // edw kanw mia arxikopoihsh gia ta matia tou kosmou
  31.    for(i = 0; i < N; i++){
  32.        pin1[i] = 0;
  33.    }
  34.    
  35.     printf("SORTED MATRIX\n");
  36.    
  37.     for(i=0;i<N;i++){
  38.        
  39.         // edw pairneis ena tyxaio ari8mo opws 8es
  40.         num = rand()%10;
  41.         // edw allazes to num kai exanes ton tyxaio ari8mo
  42.         //num = pin1[i];
  43.         //potition = i;
  44.        
  45.         // o elegxos pou sou elega na kaneis apla ton alla3a epeidh eixa kanei la8os
  46.         check = 0;
  47.         for(j=0; j<i;j++){
  48.  
  49.             if(pin1[j] == num){
  50.                 i--;
  51.                 check = 1;
  52.                 break;
  53.             }
  54.  
  55.             // what is this?
  56.             //pin1[potition] = num;
  57.         }
  58.         if(check == 1){
  59.             continue;
  60.         }
  61.      
  62.         // auth h if den xreiazetai
  63.         //if(pin1[potition-1] >= num){
  64.            
  65.             //den xreiazetai na kaneis insertion sort afou esu ftiaxneis ton pinaka
  66.             //oi sorting algorithms einai ftiagmenoi gia hdh etoimous pinakes
  67.            
  68. /*
  69.             while((pin1[potition-1] >= num) && (potition - 1 >= 0)){
  70.                 edw xaneis stoixeia epeidh den kratas kapou thn timh tou pin[position]
  71.                
  72.                 pin1[potition] = pin1[potition-1];
  73.                 potition = potition - 1;
  74.                
  75.  
  76.  
  77.             }
  78.             */
  79.  
  80.        // potition = i;
  81.        
  82.         for(j = 0; j < i; j++){
  83.             if(pin1[j] > num){
  84.                 for(k = i - 1; k >= j; k--){
  85.                     pin1[k + 1] = pin1[k];
  86.                 }
  87.                 break;
  88.             }
  89.         }
  90.            
  91.         //}
  92.         //else if(pin1[potition-1] == num){
  93.             //break;
  94.        // }
  95.         pin1[j] = num;
  96.     }
  97.    
  98.     for(i=0;i<N;i++){
  99.        
  100.         printf("Potition: %d: %d\n", i, pin1[i]);
  101.     }
  102.    
  103.    
  104.         // 2ND MATRIX
  105. //    printf("2ND MATRIX\n");
  106.    
  107.     //for(i=0;i<M;i++){
  108.         //pin2[i] = rand()%(900) + 100;
  109.     //}
  110.     //(i=0;i<M;i++){
  111.        
  112.         //printf("Number %d: %d\n", i+1, pin2[i]);
  113.     //}
  114.    
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement