Why the if condition in the following program do not follow the sequence specified? i.e, when r equals to k , either the b or g should not increment its value but it does increase its value by one.
#include <stdio.h>
int main(void){
int T;
scanf("%d",&T);
while(T>0)
{
int R,G,B,k,i,r=0,g=0,b=0,count=0;
scanf("%d %d %d",&R,&B,&G);
scanf("%d",&k);
if(k<=R || k<=G || k<=B)
{
for(i=1;i<=k;i++)
{
if(r<R && (b!=k || g!=k) )
{
r++;
}
if(b<B && (r!=k || g!=k) ) // these conditions has to be executed
{
b++;
}
if(g<G && (r!=k || b!=k) )
{
g++;
}
}
count=r+g+b;
printf("%d\n",count);
}
T--;
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire