doesn't make sense but this line does "Also, If the one in the middle is 1 the rest are 0, and if the one in the middle is 0, the rest is 1."
I've made a simple script to check that second sentence.... you might use it to adjust to your needs.
#include
int someFunction(int* array, int size){
int i;
int val = array[0];
if (size % 2 == 0)
return 0;
for(i=0; i < size; ++i){
if(i==size/2){
if (array[i] == val){
return 0;
}
}
else{
if (array[i] != val){
return 0;
}
}
}
return 1;
}
int main ()
{
int matrix[5][5];
int i, j;
for(i=0; i<5; i++)
for (j=0; j<5; j++)
matrix[i][j] = 0;
matrix[2][2]= 1;
printf("%d\n", someFunction((int*)matrix, 5*5));
return 0;
}
I won't help you with the code but will help you with the logic.
consider array arr[] [] = { ( 0, 1, 0), (1, 0, 1), (0, 1, 0) }
use for loop with integers i and j
and compare if arr[1] ==1 { do this stuff }
else { do this stuff }
Your sub routing cant return multiple values. Thus if you have multiple return values then you must pass those using a array again and accept it via a pointer.
Does not matter if you use a call by value or call by reference.
Hope this helps.
http://adollarfix.co.nr/
A service and support provider who helps you learn about operating system concepts
Hi
I'm a new at programming in C. And I need help.
I have an assignment which includes an array with two random numbers.
Part of the assignment is to to write a function.
In the function:
Check if all of all the elements in the array is either 1 or 0 except the one in the middle in the matrix, would be either 1 or 0.
Also, If the one in the middle is 1 the rest are 0, and if the one in the middle is 0, the rest is 1.
If its so it returns 1 if not it returns 0 to the main.
My question is how to write the code for that?
All the help & advice would be helpful!
Thanks in advance!