Skip to content

Instantly share code, notes, and snippets.

@RoxasShadow
Created November 19, 2012 19:31
Show Gist options
  • Save RoxasShadow/4113131 to your computer and use it in GitHub Desktop.
Save RoxasShadow/4113131 to your computer and use it in GitHub Desktop.
#include <stdio.h>
/* Niente funzioni e niente di niente, un array e un algoritmo di ordinamento bubblesort che te lo ordina in modo crescente semplicemente scambiando gli elementi.
*/
int main() {
int n;
printf("Values to add: ");
scanf("%d", &n);
if(n <= 2) {
printf("Invalid input.");
return -1;
}
int i;
int input[n];
for(i = 0; i < n; ++i) {
printf("Value: ");
scanf("%d", &input[i]);
}
int j, swap;
for(i = 0; i < n; ++i)
for(j = 0; j < n; ++j)
if(input[j] > input[i]) {
swap = input[i];
input[i] = input[j];
input[j] = swap;
}
for(i = 0; i < n; ++i)
printf("%d, ", input[i]);
printf("Max: %d\n", input[n]);
printf("Max - 1: %d\n", input[n-1]);
printf("Min: %d\n", input[0]);
printf("Min + 1: %d\n", input[1]);
getch();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment