2017德邦物流停运时间:输入一整数S(0<=s<=32767)若不在范围内重新输入要求从个位数开始分离每位占一行

来源:百度文库 编辑:查人人中国名人网 时间:2024/05/07 04:16:45
用C++编程

以下程序通过标准C++开发,经严格测试。
#include<iostream>
#include<math.h>
using namespace std;
int main(){
int s;
char *str=(char *)malloc(100*sizeof(char));
cout<<"输入s(s范围0<=s<=32767) : ";
cin>>s;
while((s<0)||(s>32767))
{
cout<<"输入错误!"<<endl;
cout<<"输入s(s范围0<=s<=32767) : ";
cin>>s;
}
str=itoa(s,str,10);
for(int a=sizeof(str)-4+log10(s);a>=0;a--)
cout<<str[a]<<endl;
}

#include <iostream.h>
int main()
{
int S = -1, temp;
do
{
cout << "Enter number S : " << endl;
cin >> S;
} while(!(S >= 0 && S <= 32767));

temp = S;
while(temp)
{
cout << temp % 10 << endl;
temp /= 10;
}

return 0;
}