Have to make a program that given an array of 7 integer from input, applies a function like this one:
void firstlasteven(int arr[], int dim, int* firstocc, int* lastocc);
that returns the position of the first and last even number or "-1" if there's none.
example input/output:
3 1 5
6
4
8
8
-8
1
This is my code so far:
Code:
#include <stdio.h>
int *primoultimopari(int arr[], int dim, int* primaocc, int* ultimaocc){
int i;
int s=0;
for(i=0;i<dim;i++){
if((arr[i]%2)==0){
if(s==0){
*primaocc=i;
s++;
}
else{
*ultimaocc=i;
}
}
}
}
int main(void){
int dimensione=7;
int i;
int A[7];
for(i=0;i<7;i++){
scanf("%d", &A[i]);
}
int prima,ultima;
primoultimopari(A[7], dimensione, &prima, &ultima);
printf("%d %d", prima,ultima);
return 0;
}
(prima is first, ultima is last.)
Any help would be much appreciated.
These are the errors i get:
Code:
Lez6Es4c72.c:28:21: warning: passing argument 1 of ‘primoultimopari’ makes pointer from integer without a cast [-Wint-conversion]
primoultimopari(A[7], dimensione, &prima, &ultima);
Lez6Es4c72.c:4:6: note: expected ‘int *’ but argument is of type ‘int’
int *primoultimopari(int arr[], int dim, int* primaocc, int* ultimaocc){
^~~~~~~~~~~~~~~