xLevel Posted February 22, 2017 Report Posted February 22, 2017 (edited) Sint date 2 masive unidimensionale x[k] si y[m]. De calculat valoarea expresiei z=(xmax-ymin)/(ymax-xmin),unde xmax si xmin sint valorile elementelor maximal si minimal din masivul x, iar ymax si ymin sint valorile elementelor maximal si minimal din masivul y. Folosirea subprogramului pentru: Determinarea valorilor elementelor maximale si minimale pentru ambele masive. Ajutati-ma va rog, macar cu idei si sugestii! Multumesc anticipat! SUNT DE ACORD SA ACHIT AJUTOR VOSTRU,NE INTELEGEM!!! Exemplu de program,adica trebuie de folosit limbajul simplu ca in program Trebuie de folosit printf,scanf si randomize() Edited February 22, 2017 by xLevel Quote
u0m3 Posted February 22, 2017 Report Posted February 22, 2017 #include <stdio.h> int min(int vlen, int* v) { int min = v[0]; // assume vlen > 0 // loop over vector and if we find a // smaller value than the current // smallest value, that becomens // the new minimum for(int i = 1; i < vlen; ++i) if(v[i] < min) min = v[i]; return min; } int max(int vlen, int* v) { int max = v[0]; // assume vlen > 0 // loop over vector and if we find a // bigger value than the current // biggest value, that becomens // the new maximum for(int i = 1; i < vlen; ++i) if(v[i] > max) max = v[i]; return max; } int main(int argc, char* argv[]) { // Variables int xlen; // x length int ylen; // y length int x[50]; int y[50]; int xmin; int xmax; int ymin; int ymax; // Read xlen printf("Introduceti dimensiunea masivului X (maxim 50): "); scanf("%d", &xlen); // Read x for(int i = 0; i < xlen; ++x) { printf("x[%d] = ", i); scanf("%d", &x[i]); } // Read ylen printf("Introduceti dimensiunea masivului Y (maxim 50): "); scanf("%d", &ylen); // Read y for(int i = 0; i < ylen; ++x) { printf("y[%d] = ", i); scanf("%d", &y[i]); } // Find mins and maxs xmin = min(xlen, x); xmax = max(xlen, x); ymin = min(ylen, y); ymax = max(ylen, y); // Check for division by 0 if(ymax - xmin == 0) printf("Eroare: impartire la 0!\n"); else printf("z = (xmax - ymin) / (ymax - xmin) = %d", (xmax - ymin) / (ymax - xmin)); return 0; } 2 Quote