M and n has a statistical number between the number which is the sum of the digits 5

int Count(int m, int n)
{
 int count,count1,count2=0;
 if((10<=m&&m<=99)&&(10<=n&&n<=99))
 {
  for(int i=m;i<=n;i++)
  {
   if((i/10)+(i%10)==5)
   {
    count1++;
   }
  }
  return(count1);
 }
 else if((100<=m&&m<=999)&&(100<=n&&n<=999))
 {
  for(int i=m;i<=n;i++)
  {
   if((i/100)+(i%10%10)+(i/10%10)==5)
   {
    count2++;
   }
  }
  return(count2);
 }
 else if((10<=m&&m<=99)&&(100<=n&&n<=999))
 {
  for(int i=m;i<=n;i++)
  { 
   if(10<=i&&i<=99)
   {
   if((i/10)+(i%10)==5)
   {
    count1++;
   }
   }
   else if(100<=i&&i<=999)
   {
   if((i/100)+(i%10%10)+(i/10%10)==5)
   {
    count2++;
   }
   }
  }
  return(count2+count1);
 }
}
Published 45 original articles · won praise 36 · views 821

Guess you like

Origin blog.csdn.net/huangziguang/article/details/104434747