Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my task:
Given an integer matrix of size N. Find the set of the smallest elements of its odd rows and large elements of its even rows.
I don't really know what am i doing wrong.

What I have tried:

#include<conio.h>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int size;
int min(int *array[][50])
{
	int i,j,min_e=0;
	for (i = 1; i < size; i++)
	{
		for (j = 1; j < size; j++)
		{
			if (array[i][j] < array[min_e])//operand types are incompatible ("int *" and "int **")
			{
				min_e = i;
			}
			return min_e;
		}
	}
}
int x(int array[][50])
{
	int i, j,sum_e=0;
	for (i = 0; i < size; i++)
	{
		for (j = 0; j < size; j++)
		{
			if (i % 2 == 0)
			{
				sum_e += min(array);//argument of type "int (*)[50]" is incompatible with parameter of type "int *(*)[50]
			}
			return sum_e;
		}
	}
	return 0;
}
int max(int array[][50])
{
	int i, j, max_e = 0;
	for (i = 1; i < size; i++)
	{
		for (j = 1; j < size; j++)
		{
		 if (array[i][j] > array[max_e])//operand types are incompatible ("int *" and "int **")			
 
		max_e = i;
		}
		return max_e;
	}
}
int y( int array[50][50])
{
	int i, j, sum_o = 0, o = 0;
	for (i = 0; i < size; i++)
	{
		for (j = 0; j < size; j++)
		{
			if (array[i][j] % 2 == 1)
			{
				sum_o += max(array);//argument of type "int (*)[50]" is incompatible with parameter of type "int *(*)[50]	

			}
		}
		return sum_o;
	}
	return 0;
}
int main()
{
	int array[50][50], i, j;
	printf("\n Size of array: ");
	scanf_s("\n %d", &size);
	for (i = 0; i < size; i++)
	{
		for (j = 0; j < size; j++)
		{
			printf("\n array[%d][%d]: ",i,j);
			scanf_s("\n %d", array[i][j]);
		}
	}
	printf("\n Sum of even-numbered elements \n: ", x(array));
	printf("\n Sum of odd-numbered elements \n: ", y(array));
	_getch();
	return 0;
}
Posted
Updated 11-Nov-17 7:49am

1 solution

That is a relly simple task, so I give you only some tips:

use clearer var and function names, not x()
use debug output (printf) in critical code pathes like function call and if statement
(remove oe comment out when not more needed)
write some test data, with simple array so you can debug your code

one bug is that your max_e is wrong. You assign the index not the value.
C++
if (array[i][j] > max_e ) {
printf("new max found: %d", array[i][j] );
max_e = array[i][j];//adding one
}
should be correct.

You should also guard that size cant be greater than 50.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900