Untitled
unknown
plain_text
a year ago
679 B
14
Indexable
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> void sortare(float v[], int n, int(*criteriu)(float, float)) { int i, j; for (i = 0; i < n - 1; i++) for (j = i + 1; j < n; j++) if ((criteriu(v[i], v[j])) == 0) { float aux = v[i]; v[i] = v[j]; v[j] = aux; } } int cresc(float a, float b) { return (a < b) ? 1 : 0; } int descresc(float a, float b) { return (a < b) ? 0 : 1; } void main() { float v[20]; int n, i; printf("n= "); scanf("%i", &n); for (i = 0; i < n; i++) { printf("v[%i]=", i); scanf("%f", &v[i]); } sortare(v, n, cresc); for (i = 0; i < n; i++) { printf("%.2f ", v[i]); } }
Editor is loading...
Leave a Comment