You are viewing a single comment's thread. Return to all comments →
Similar approach, but using a function:
#include <stdio.h> #include <stdlib.h> int fruit_counter(int house0, int house1, int three, int* fruit, int num_fruits){ int fruit_loc, count = 0; for(int i = 0; i < num_fruits; ++i){ fruit_loc = three+fruit[i]; if(fruit_loc >= house0 && fruit_loc <= house1){ ++count; } } return count; } int main(){ int s, t, a, b, m ,n; int apple_count, orange_count; scanf("%d %d",&s,&t); scanf("%d %d",&a,&b); scanf("%d %d",&m,&n); int* apple = malloc(m*sizeof(int)); for(int i = 0; i < m; ++i){ scanf("%d",&apple[i]); } int *orange = malloc(n*sizeof(int)); for(int i = 0; i < n; ++i){ scanf("%d",&orange[i]); } apple_count = fruit_counter(s, t, a, apple, m); orange_count = fruit_counter(s, t, b, orange, n); printf("%d\n%d\n", apple_count, orange_count); return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Apple and Orange
You are viewing a single comment's thread. Return to all comments →
Similar approach, but using a function: