Jump to content
mironion

Program in limbajul C

Recommended Posts

Posted (edited)
4 hours ago, mironion said:

Un program ce calculeaza suma si numarul elementelor pozitive din coloane pare.

  1. Acesta este un forum, nu "ghiseul" unde plasezi comanda la McDonald's... Exprima si tu, in cuvinte, preferabil si cat de cat coerent, ce doresti.
  2. Acesta este un forum, nu fabrica de facut teme, nu e colegu' de clasa pe care il ameniti ca il bati daca nu iti face tema. Nu te astepta sa ne scrii enuntul problemei si noi sa ti-o rezolvam; arata si tu ca ti-ai dat un minim interes...
Edited by u0m3
  • Upvote 6
Posted
On 11/8/2018 at 11:55 PM, u0m3 said:
  1. Acesta este un forum, nu "ghiseul" unde plasezi comanda la McDonald's... Exprima si tu, in cuvinte, preferabil si cat de cat coerent, ce doresti.
  2. Acesta este un forum, nu fabrica de facut teme, nu e colegu' de clasa pe care il ameniti ca il bati daca nu iti face tema. Nu te astepta sa ne scrii enuntul problemei si noi sa ti-o rezolvam; arata si tu ca ti-ai dat un minim interes...

Mdaa.Mai ajutat foarte mult! Îți mulțumesc 

 

  • Downvote 2
Posted (edited)
#define E_ASSIGNMENT_OK                            0
#define E_ASSIGNMENT_INVALID_MATRIX_DIMENSIONS    -1
#define E_ASSIGNMENT_INVALID_RESULT_POINTER       -2

struct result_holder
{
	float sum_0based_index;
	float sum_1based_index;
	unsigned int count_0based_index;
	unsigned int count_1based_index;
};

int assignment(float const * const matrix, unsigned int const num_rows, unsigned int const num_cols, result_holder * const result)
{
	unsigned int idx = 0
	
	if(num_cols <= 0 || num_rows <= 0)
		return E_INVALID_MATRIX_DIMENSIONS;
	
	if(result_holder == NULL)
		return E_INVALID_RESULT_POINTER;
	
	result.sum_0based_index = 0;
	result.sum_1based_index = 0;
	result.count_0based_index = 0;
	result.count_1based_index = 0;
	
	for(unsigned int row = 0; row < num_rows; ++row)
	{
		for(unsigned int col = 0; col < num_cols; ++col)
		{
			idx = row * num_cols + col;
			if(col % 2 == 0 && matrix[idx] > 0)
			{
				result.sum_0based_index += matrix[idx];
				++result.count_0based_index;
			}
			else
			{
				result.sum_1based_index += matrix[idx];
				++result.count_1based_index;
			}
		}
	}
	return E_OK;
}

 

Edited by u0m3
Posted
8 hours ago, mironion said:

Mdaa.Mai ajutat foarte mult! Îți mulțumesc 

 

Cu placere! Si vezi ca e "M-ai ajutat foarte mult".

 

 

Acum serios, eu pot sa iti dau si mura-n gura, dar nu vei invata nimic asa...

Spoiler

#define E_ASSIGNMENT_OK                            0
#define E_ASSIGNMENT_INVALID_MATRIX_DIMENSIONS    -1
#define E_ASSIGNMENT_INVALID_RESULT_POINTER       -2

struct result_holder
{
	float sum_0based_index;
	float sum_1based_index;
	unsigned int count_0based_index;
	unsigned int count_1based_index;
};

int assignment(float const * const matrix, unsigned int const num_rows, unsigned int const num_cols, result_holder * const result)
{
	unsigned int idx = 0
	
	if(num_cols <= 0 || num_rows <= 0)
		return E_INVALID_MATRIX_DIMENSIONS;
	
	if(result_holder == NULL)
		return E_INVALID_RESULT_POINTER;
	
	result.sum_0based_index = 0;
	result.sum_1based_index = 0;
	result.count_0based_index = 0;
	result.count_1based_index = 0;
	
	for(unsigned int row = 0; row < num_rows; ++row)
	{
		for(unsigned int col = 0; col < num_cols; ++col)
		{
			idx = row * num_cols + col;
			if(col % 2 == 0 && matrix[idx] > 0)
			{
				result.sum_0based_index += matrix[idx];
				++result.count_0based_index;
			}
			else
			{
				result.sum_1based_index += matrix[idx];
				++result.count_1based_index;
			}
		}
	}
	return E_OK;
}

 

 

  • Like 1
Posted
19 hours ago, u0m3 said:

Cu placere! Si vezi ca e "M-ai ajutat foarte mult".

 

 

Acum serios, eu pot sa iti dau si mura-n gura, dar nu vei invata nimic asa...

  Reveal hidden contents


#define E_ASSIGNMENT_OK                            0
#define E_ASSIGNMENT_INVALID_MATRIX_DIMENSIONS    -1
#define E_ASSIGNMENT_INVALID_RESULT_POINTER       -2

struct result_holder
{
	float sum_0based_index;
	float sum_1based_index;
	unsigned int count_0based_index;
	unsigned int count_1based_index;
};

int assignment(float const * const matrix, unsigned int const num_rows, unsigned int const num_cols, result_holder * const result)
{
	unsigned int idx = 0
	
	if(num_cols <= 0 || num_rows <= 0)
		return E_INVALID_MATRIX_DIMENSIONS;
	
	if(result_holder == NULL)
		return E_INVALID_RESULT_POINTER;
	
	result.sum_0based_index = 0;
	result.sum_1based_index = 0;
	result.count_0based_index = 0;
	result.count_1based_index = 0;
	
	for(unsigned int row = 0; row < num_rows; ++row)
	{
		for(unsigned int col = 0; col < num_cols; ++col)
		{
			idx = row * num_cols + col;
			if(col % 2 == 0 && matrix[idx] > 0)
			{
				result.sum_0based_index += matrix[idx];
				++result.count_0based_index;
			}
			else
			{
				result.sum_1based_index += matrix[idx];
				++result.count_1based_index;
			}
		}
	}
	return E_OK;
}

 

 

Iti multumesc! eu daca sincer mi-am facut prima parte asta e a2-a care am intrebat

 

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...