Birthday Chocolate
Question :-
https://www.hackerrank.com/challenges/the-birthday-bar/problem
Solution in C language :-
#include<stdio.h>
int main(){
int n,i,j,m,d,sum=0,c=0;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
scanf("%d",&d);
scanf("%d",&m);
for(i=0;i<n;i++){
for(j=i;j<m+i;j++){
sum=sum+a[j];
}
if(sum==d){
c++;
}
sum=0;
}
printf("%d",(c));
return 0;
}
Comments
Post a Comment