幼儿园分苹果(/)
//平分物品 #include<iostream> using namespace std; int main(){ int apple_number=60;//60个苹果 int people=12;//12个人 int apple_per_people;//每个人分多少个苹果 if(people!=0) { apple_per_people=apple_number/people; cout<<"平均分配,每个人得到"<<apple_per_people<<"个苹果"<<endl; } else cout<<"除数为零,出现异常"<<endl; return 0; }
注意:一旦遇到除法运算,一定要先判断除数是否为零