Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define N 10
- #define M 15
- int main(){
- int pin1[N], pin2[M];
- int j, i, k, check, num, num2, check2;
- //1ST MATRIX
- for(i=0;i<N;i++){
- num = rand()% (900) + 100;
- //ELEGXOS GIA IDIA STOIXEIA
- check=0; //arxikopoiw ton deikth mou
- for(j=0;j<i;j++){
- if(pin1[j] == num){
- i--; //epestrepse to 1 mia thesh pisw
- check=1; // check = 1 ---> True < exw brei aritmo iso me to num >
- break; // bges apo thn loopa
- }
- }
- if(check == 1){ //me to deytero perasma (gia i==1) tha brei ton check == 1 opote den tha
- continue; //ksanakanei ton elegxo kai tha sinexisei gia tin epomenh for...
- }
- //METAKINISH ARITHMWN MIA THESH BRWSTA (otan brethei megaliteros h isos)
- for(j=0;j<i;j++){ // for (1)
- if(pin1[j] > num){ //an o proigoumenos einai megalitero tou num tote
- for(k = i-1; k>=j; k--){ //metakinise ta stoixeia mia thesh brwsta gia na eleftherwseis ti thesh
- pin1[k + 1] = pin1[k]; // metakinei ton megalitero sthn epomenh thesh
- }
- break; //teleiwnoun oi metakiniseis opote kanei break kai bgainei apo thn for(1)
- }
- }
- pin1[j] = num; //topothetei kathe fora to swsto arithmo sth kenh thesh pou kaname
- }
- //EKTYPWSH TOU PINAKA
- for(i=0;i<N;i++){
- printf("Potition %d: %d\n", i, pin1[i]);
- }
- //2ND MATRIX
- for(i=0;i<N;i++){
- num2 = rand()%10;
- //ELEGXOS 2OU PINAKA
- check2 = 0;
- for(j=0;j<i;j++){
- if(pin2[j] == num2){
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement