Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 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. int pin1[N], pin2[M];
  11. int j, i, k, check, num, num2, check2;
  12.  
  13. //1ST MATRIX
  14.  
  15. for(i=0;i<N;i++){
  16.  
  17. num = rand()% (900) + 100;
  18.  
  19. //ELEGXOS GIA IDIA STOIXEIA
  20. check=0; //arxikopoiw ton deikth mou
  21. for(j=0;j<i;j++){
  22. if(pin1[j] == num){
  23. i--; //epestrepse to 1 mia thesh pisw
  24. check=1; // check = 1 ---> True < exw brei aritmo iso me to num >
  25. break; // bges apo thn loopa
  26. }
  27. }
  28. if(check == 1){ //me to deytero perasma (gia i==1) tha brei ton check == 1 opote den tha
  29. continue; //ksanakanei ton elegxo kai tha sinexisei gia tin epomenh for...
  30. }
  31.  
  32. //METAKINISH ARITHMWN MIA THESH BRWSTA (otan brethei megaliteros h isos)
  33.  
  34. for(j=0;j<i;j++){ // for (1)
  35. if(pin1[j] > num){ //an o proigoumenos einai megalitero tou num tote
  36. for(k = i-1; k>=j; k--){ //metakinise ta stoixeia mia thesh brwsta gia na eleftherwseis ti thesh
  37. pin1[k + 1] = pin1[k]; // metakinei ton megalitero sthn epomenh thesh
  38. }
  39. break; //teleiwnoun oi metakiniseis opote kanei break kai bgainei apo thn for(1)
  40. }
  41.  
  42. }
  43.  
  44. pin1[j] = num; //topothetei kathe fora to swsto arithmo sth kenh thesh pou kaname
  45. }
  46.  
  47. //EKTYPWSH TOU PINAKA
  48.  
  49. for(i=0;i<N;i++){
  50. printf("Potition %d: %d\n", i, pin1[i]);
  51. }
  52.  
  53. //2ND MATRIX
  54.  
  55. for(i=0;i<N;i++){
  56.  
  57. num2 = rand()%10;
  58.  
  59. //ELEGXOS 2OU PINAKA
  60.  
  61. check2 = 0;
  62. for(j=0;j<i;j++){
  63. if(pin2[j] == num2){
  64.  
  65.  
  66. }
  67. }
  68.  
  69.  
  70.  
  71. }
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81. return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement