Professional Documents
Culture Documents
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int n;
scanf("%d", &n);
float k[n];
float p[n];
{
float a = 0.1f * rand() / RAND_MAX;
float b = 0.1f * rand() / RAND_MAX;
if (a < b)
{
k[i] = a;
p[i] = b;
else
{
k[i] = b;
p[i] = a;
}
}
{
float temp = k[i];
k[i] = k[j];
k[j] = temp;
}
if (k[i] > p[j])
}
}
}
int i = 0;
int j = 0;
int c = 0;
int res = 0;
while (i < n && j < n)
{
if (k[i] <= p[j])
{
c++;
i++;
}
else
{
c--;
j++;
}
if (res < c)
{
res = c;
}
}
// intervals;
printf("MAX overlap: %d\n", res);
return 0;
}
Output:
PS C:\Users\HP\daa lab> cd "c:\Users\HP\daa lab\" ; if ($?)
{ gcc lab5.c -o lab5 } ; if ($?) { .\lab5 }
55
Random numbers generated between 0 and 1:
0.042103 0.062221
0.001306 0.051506
0.051207 0.093161
0.017252 0.018323
0.036940 0.064727
0.077554 0.084173
0.055083 0.062038
0.029969 0.065310
0.009690 0.020267
0.076766 0.080242
0.049098 0.087976
0.046315 0.062273
0.006946 0.093472
0.006742 0.062447
0.050508 0.095712
0.009235 0.048982
0.023655 0.076049
0.016736 0.041252
0.026899 0.072240
0.001642 0.088415
0.039445 0.093481
0.036506 0.062499
0.057933 0.085525
0.008661 0.028690
0.012851 0.028727
0.063988 0.081466
0.022187 0.053108
0.053380 0.066591
0.041011 0.055531
0.001328 0.063552
0.074963 0.094809
0.058858 0.059713
0.001956 0.064074
0.057601 0.093289
0.039952 0.046477
0.046040 0.077822
0.059658 0.098901
0.023692 0.086145
0.020588 0.029167
0.071984 0.088812
0.041212 0.099710
0.053502 0.069079
0.033879 0.070727
0.016810 0.070992
0.047276 0.083883
0.036485 0.044688
0.016486 0.030204
0.081045 0.089956
0.079479 0.087057
0.035374 0.065233
0.041951 0.086105
0.061141 0.072283
0.003897 0.042582
0.015552 0.089950
0.011744 0.025782
MAX overlap: 50