+ -
当前位置:首页 → 问答吧 → 求助C语言

求助C语言

时间:2011-09-09

来源:互联网

才看C的教程没两天,基础薄弱。问个弱弱的问题,以下两段代码为什么
代码:
volume = height * length * width;
      weight = (volume + 165) / 166;
的位置不同输出结果会不一样的 ?

代码1:
代码:
#include <stdio.h>


int main(void)
{
   int height,length,width,volume,weight;

      
      
         printf("Input the box's height:\n");
            scanf("%d",&height);
         printf("Input the box's length:\n");
            scanf("%d",&length);
         printf("Input the box's width:\n");
            scanf("%d",&width);
            /*放在这里*/
            volume = height * length * width;
      weight = (volume + 165) / 166;
            
         printf("The box's height is : %d\n",height);
                     printf("The box's length is : %d\n",length);
               printf("The box's width  is : %d\n",width);
               
                  printf("The box's volume is : %d\n",volume);
                     printf("the box's weight is : %d \n",weight);
   
   
   
   return 0;
}

输出结果:
代码:
Input the box's height:
10
Input the box's length:
8
Input the box's width:
12
The box's height is : 10
The box's length is : 8
The box's width  is : 12
The box's volume is : 960
the box's weight is : 6

代码2
代码:
#include <stdio.h>


int main(void)
{
   int height,length,width,volume,weight;

      /*放在这里*/
      volume = height * length * width;
      weight = (volume + 165) / 166;
      
         printf("Input the box's height:\n");
            scanf("%d",&height);
         printf("Input the box's length:\n");
            scanf("%d",&length);
         printf("Input the box's width:\n");
            scanf("%d",&width);
            
            
            
         printf("The box's height is : %d\n",height);
                     printf("The box's length is : %d\n",length);
               printf("The box's width  is : %d\n",width);
               
                  printf("The box's volume is : %d\n",volume);
                     printf("the box's weight is : %d \n",weight);
   
   
   
   return 0;
}

输出结果
代码:
Input the box's height:
10
Input the box's length:
8
Input the box's width:
12
The box's height is : 10
The box's length is : 8
The box's width  is : 12
The box's volume is : 1835941696
the box's weight is : 11059890

作者: mawith   发布时间: 2011-09-09