SHARE
TWEET

Untitled

a guest May 23rd, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <math.h>
  5.  
  6. void fillIntArray(int iFld[], int length, int og, int ug);
  7. void putArraysTogether(int iFld[], int a[], int aLength, int b[], int bLength);
  8. void printArray(int iFld[], int length);
  9. void sortArray(int iFld[], int length, int max);
  10. void deleteDuplicates(int iFld[], int *length);
  11.  
  12. int main()
  13. {
  14.   srand(time(NULL));
  15.   int aLength=123;
  16.   int aOg=400;
  17.   int aUg=200;
  18.   int a[aLength];
  19.   int bLength=230;
  20.   int bOg=300;
  21.   int bUg=100;
  22.   int b[bLength];
  23.  
  24.   int cLength=aLength+bLength;
  25.   int c[cLength];
  26.  
  27.   fillIntArray(a, aLength, aOg, aUg);
  28.   fillIntArray(b, bLength, bOg, bUg);
  29.  
  30.   putArraysTogether(c, a, aLength, b, bLength);
  31.  
  32.   printArray(c, cLength);
  33.  
  34.   sortArray(c, cLength, aOg+bOg);
  35.   printArray(c, cLength);
  36.  
  37.   deleteDuplicates(c, &cLength);
  38.   printArray(c, cLength);
  39.   return 0;
  40. }
  41.  
  42. void fillIntArray(int iFld[], int length, int og, int ug)
  43. {
  44.   for(int i=0; i<length; i++) iFld[i]=rand()%(og-ug+1)+ug;
  45. }
  46.  
  47. void putArraysTogether(int iFld[], int a[], int aLength, int b[], int bLength)
  48. {
  49.   int counter=0;
  50.   for(int i=0; i<aLength; i++)
  51.   {
  52.     iFld[counter]=a[i];
  53.     counter++;
  54.   }
  55.   for(int i=0; i<bLength; i++)
  56.   {
  57.     iFld[counter]=b[i];
  58.     counter++;
  59.   }
  60. }
  61.  
  62. void printArray(int iFld[], int length)
  63. {
  64.   printf("%d", iFld[0]);
  65.   for(int i=1; i<length; i++) printf(", %d", iFld[i]);
  66.   printf("\n");
  67. }
  68.  
  69. void sortArray(int iFld[], int length, int max)
  70. {
  71.   int min=max;
  72.   int minPoint;
  73.   int help;
  74.   for(int i=0; i<length-1; i++)
  75.   {
  76.     for(int i2=i; i2<length; i2++)
  77.     {
  78.       if(iFld[i2]<min)
  79.       {
  80.         min=iFld[i2];
  81.         minPoint=i2;
  82.       }
  83.     }
  84.     min=max;
  85.     help=iFld[i];
  86.     iFld[i]=iFld[minPoint];
  87.     iFld[minPoint]=help;
  88.   }
  89. }
  90.  
  91. void deleteDuplicates(int iFld[], int *length)
  92. {
  93.   for(int i = 0; i<((*length/2)+1); i++)
  94.   {
  95.     for(int i = 0; i<*length; i++)
  96.     {
  97.       for(int i2 = (i+1); i2<*length; i2++)
  98.       {
  99.         if(iFld[i]==iFld[i2])
  100.         {
  101.           for(int i3 = i2; i3<(*length-1); i3++)
  102.           {
  103.             iFld[i3] = iFld[i3+1];
  104.           }
  105.           (*length)--;
  106.         }
  107.       }
  108.     }
  109.   }
  110. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top