打印输入中单词长度的直方图

maxvalue=0;
      for(i=1;i<MAXWORD;++i)
          if(wl[i]>maxvalue)
             maxvalue=wl[i];
      for(i=1;i<MAXWORD;++i)
      {
      printf("%5d-%5d:",i,wl[i]);
      if(wl[i]>0)                                                     
      {
         if((len=wl[i]+MAXHIST/maxvalue)<=0)  
         len=1;  
      }
      else 
        len=0;                                                        
      while(len>0)
        {
        putchar('*');
        --len;                                 //为什么要--len?
        }
        putchar('\n');   
      }
      if(ovflow>0)
         printf("there are %d words >=%d\n",ovflow,MAXWORD);
 
问题:1
if((len=wl[i]*MAXHIST/maxvalue)<=0)
      len=1;   这段话表示什么意思?
问题:2
         while(len>0)
             {
                 putchar('*');
                 --len;
             }这段话与上面的if((len=wl[i]*MAXHIST/maxvalue)<=0)有什么关系吗?
问题3:
为什么一定要求最大数值?且以此为标准?
 for(i=1;i<MAXWORD;++i)
          if(wl[i]>maxvalue)
             maxvalue=wl[i];
}


慕粉3368274
浏览 1428回答 0
0回答
打开App,查看更多内容
随时随地看视频慕课网APP