HackerRank C- Apple and Orange
Complete the countApplesAndOranges function in the editor below. It should print the number of apples and oranges that land on Sam's house, each on a separate line.
countApplesAndOranges has the following parameter(s):
s: integer, starting point of Sam's house location.
t: integer, ending location of Sam's house location.
a: integer, location of the Apple tree.
b: integer, location of the Orange tree.
apples: integer array, distances at which each apple falls from the tree.
oranges: integer array, distances at which each orange falls from the tree.
- #include<stdio.h>
- int main(){ int s;
- int t,count1=0,count2=0;
- scanf("%d %d",&s,&t);
- int a;
- int b;
- scanf("%d %d",&a,&b);
- int m;
- int n;
- scanf("%d %d",&m,&n);
- int temp;
- for(int apple_i = 0; apple_i < m; apple_i++)
- { scanf("%d",&temp);
- if(temp+a>=s && temp+a<=t)
- { count1++; }
- }
- for(int orange_i = 0; orange_i < n; orange_i++)
- { scanf("%d",&temp);
- if(temp+b>=s && temp+b<=t)
- { count2++; }
- }
- printf("%d\n",count1);
- printf("%d",count2); return 0;
- }