HackerRank C- Birthday Chocolate



Complete the birthday function in the editor below. It should return an integer denoting the number of ways Lily can divide the chocolate bar.

birthday has the following parameter(s):

s: an array of integers, the numbers on each of the squares of chocolate
d: an integer, Ron's birth day
m: an integer, Ron's birth month



  1. #include<stdio.h>
  2. int main()
  3. {
  4. int n,d,m,sum=0,c=0,k=0,b=0;
  5. scanf("%d",&n);
  6. int a[n];
  7. for(int i=0;i<n;i++)
  8. {
  9. scanf("%d",&a[i]);
  10. }
  11. scanf("%d",&d);
  12. scanf("%d",&m);
  13. while(b!=1)
  14. {
  15. for(int j=1;j<=m;j++)
  16. {
  17. sum=sum+a[k];
  18. k++;
  19. }
  20. if(sum==d)
  21. {
  22. c++;
  23. }
  24. if(k>n)
  25. {
  26. b=1;
  27. }
  28. sum=0;
  29. k=k-m+1;
  30. }
  31. printf("%d",c);
  32. }

download android app