Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18].

Write it in ANSI C

tHIS IS WHAT i TRIED, BUT IT HAS MANY FLAWS. Majorly that [2,3] will be omitted if [1,5] is present. But[2,4] and [3,6] will not show [2,6]

```
#include<stdio.h>
int main()
{
char q;
int a[20],b[20],c[20],d[20],i,j,k;
for(i=0;i<20;i++)
{
puts("enter lower limit of interval");
scanf("%d",&a[i]);
puts("enter upper limit of interval");
scanf("%d",&b[i]);
}
for(k=0;k<i;k++)
{
for(j=0;j<20;j++)
{
if((a[j]>a[k])|(b[j]<b[k]))
{
c[i]=a[j];
d[i]=b[j];
}
}
}
for(k=0;k<i;k++)
{
printf("%d %d \n",c[k],d[k]);
}
return 0;
}
```