#include <cstdlib>
#include <iostream>
#include <sstream>
using namespace std;
int CharToInt(char chr)
{
stringstream ss;
int N;
ss << chr;
ss >> N;
return N;
}
int main(int argc, char *argv[])
{
int Sum = 0;
string str;
while(true)
{
cout << "Please input a number: ";
getline(cin,str);
if(str == "0")
{
break;
}
for(int i=0; i<str.length(); i++)
{
if(i % 2 == 0)
{
Sum = Sum + CharToInt(str[i]);
}
else
{
Sum = Sum - CharToInt(str[i]);
}
}
if(Sum == 0)
{
cout << str << " is a multiple of 11..." << endl;
}
else
{
cout << str << " is not a multiple of 11..." << endl;
}
Sum = 0;
}
system("PAUSE");
return EXIT_SUCCESS;
}
沒有留言:
張貼留言