Skip to content

Instantly share code, notes, and snippets.

@Rio-Nyx
Created February 1, 2020 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rio-Nyx/8632fe52418b5526e77a6a1ddaaa92f4 to your computer and use it in GitHub Desktop.
Save Rio-Nyx/8632fe52418b5526e77a6a1ddaaa92f4 to your computer and use it in GitHub Desktop.
/*
Output the pairs of elements with the smallest difference. If there are multiple pairs,
output all of them in ascending order, all on the same line with just a single space between each pair of numbers.
A number may be part of two pairs when paired with its predecessor and its successor.
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int n,min,j,i;
long int arr[n],t;
scanf("%d",&n);
long int arr_new[n],arr_last[n];
for (i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
for (i=0;i<n;i++)
{
for (j=0;j<n;j++)
{
if (arr[j]>arr[j+1])
{
t=arr[j];
arr[j]=arr[j+1];
arr[j+1]=t;
if(arr[j+2]='\0')
break;
}
}
}
for (i=0;i<n;i++)
{
arr_new[i]=arr[i+1]-arr[i];
if(arr[i+2]='\0')
break;
}
min=arr_new[0];
for (i=0;i<n;i++)
{
if(min>=arr_new[i])
{
min=arr_new[i];
}
if(arr_new[i+1]='\0')
break;
}
j=0;
for (i=0;i<n;i++)
{
if(min=arr_new[i])
{
arr_last[j]=arr[i];
arr_last[j+1]=arr[i+1] ;
j+=2;
//if (arr[i+2]='\0')
// break;
}
}
for (i=0;i<n;i++)
{
printf("%ld",arr_last[i]);
if(arr_last[i+1]='\0')
break;
}
}
@Rio-Nyx
Copy link
Author

Rio-Nyx commented Feb 1, 2020

this is a wrong one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment