Jump to content
xLevel

Ajutor va rog! C++ Functii,subprograme[Platesc bani!!!]

Recommended Posts

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()

Eae0A89B.jpg955c42C4.jpg

Edited by xLevel
Link to comment
Share on other sites

#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;
}

 

  • Upvote 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...