測定11的倍數
題目:從檔案讀取數字,可以判斷1000位數的數字是否為11的倍數Description
Your job is, given a positive number N, determine if it is a multiple of eleven.
Input
The input is a file such that each line contains a positive number. A line containing the number 0 is the end of the input. The given numbers can contain up to 1000 digits.
Output
The output of the program shall indicate, for each input number, if it is a multiple of eleven or not.
Sample Input
112233
30800
2937
323455693
5038297
112234
0
Sample Output
112233 is a multiple of 11.
30800 is a multiple of 11.
2937 is a multiple of 11.
323455693 is a multiple of 11.
5038297 is a multiple of 11.
112234 is not a multiple of 11.#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
//ifstream cin("numbers.txt",ios::in);
string s;
while (cin >> s) {
if(s=="0") break;
int sum={0,0};
for (int i=0; i<s.length(); i++) {
int n1 = s;
sum = sum + n1 -'0';
}
if ((sum-sum)%11==0)
cout <<s << " is a multiple of 11.\n";
else
cout <<s << " is not a multiple of 11.\n";
}
//system("pause");
return 0;
}
頁:
[1]