我的程序是
#include <stdio.h>
int main()
{int hours,salary,q,z;
float average;
int pp=0;
int a,b,c;
scanf("%d %d",&salary,&hours);
average=(float)salary/hours;
printf("%.2f\n",average);
q=average+0.5;
printf("%d\n",q);
z=q*q;
a=z%1000/100;
b=z%100/10;
c=z%10;
while(z!=0)
{
pp++;
z/=10;
}
printf("%d\n",pp);
printf("%d %d %d",a,b,c);
return 0;
}
我知道整型数z溢出了,该如何避免(只允许用int和float)
#include <stdio.h>
int main()
{int hours,salary,q,z;
float average;
int pp=0;
int a,b,c;
scanf("%d %d",&salary,&hours);
average=(float)salary/hours;
printf("%.2f\n",average);
q=average+0.5;
printf("%d\n",q);
z=q*q;
a=z%1000/100;
b=z%100/10;
c=z%10;
while(z!=0)
{
pp++;
z/=10;
}
printf("%d\n",pp);
printf("%d %d %d",a,b,c);
return 0;
}
我知道整型数z溢出了,该如何避免(只允许用int和float)