Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
CV09-2
//clang 6.0.0 #include <stdio.h> #include <stdlib.h> struct TVector { double *iDataPtr; size_t iPocet; }; int ctivector(struct TVector*aVectorPtr); int minmax(struct TVector aVector, double *aPtrMin, double *aPtrMax); int main(void) { struct TVector Vector; if(ctivector(&Vector) == -1) return 1; double min, max; if(minmax(Vector, &min, &max) == -1) { free(Vector.iDataPtr); printf("Chyba: Chybne parametry funkce minmax!\n"); return 1; } free(Vector.iDataPtr); printf("min=%f max=%f\n", min, max); return 0; } int ctivector(struct TVector *aVectorPtr) { if(aVectorPtr == NULL) return -1; size_t n; printf("Zadej pocet dat: "); if(scanf("%zu", &n) != 1) { printf("Chyba cteni poctu dat!\n"); return -1; } double *p = malloc(n * sizeof(double)); if(p == NULL) { printf("Chyba alokace pameti!\n"); return -1; } printf("Zadej %zu cisel:\n ", n); for(size_t i = 0; i < n; ++i) { if(scanf("%lf", p + i) != 1) { printf("Chyba cteni vstupnich dat!\n"); free(p); return -1; } } aVectorPtr->iDataPtr = p; aVectorPtr->iPocet = n; return 0; } int minmax(struct TVector aVector, double *aPtrMin, double *aPtrMax) { if(aVector.iDataPtr == NULL || aPtrMin == NULL || aPtrMax == NULL) return -1; double min, max; min = aVector.iDataPtr[0]; max = aVector.iDataPtr[0]; for(size_t i = 1; i < aVector.iPocet; ++i) { if(aVector.iDataPtr[i] > max) max = aVector.iDataPtr[i]; else if(aVector.iDataPtr[i] < min) min = aVector.iDataPtr[i]; } *aPtrMin = min; *aPtrMax = max; return 0; }
run
|
edit
|
history
|
help
0
Recorrido matriz bidimensional y busqueda valor
Herout (67) - 2+
Cvičenie -č.5-UDP
Bucles: Suma de n números tecleados por el usuario
Bucles: Euclides
vyměna proměnych pomoci parametru
prog0
char xor
Code
funny stack overflow