Problem6:判斷是否為 11 的倍數(14%)
Solomon
posted @ 2010年8月14日 03:31
in 98程式設計模擬試題
, 1268 阅读
給一個正整數 n,請寫一個程式,判斷 n 是否為 11 的倍數?
輸入說明:第一行的數字,表示有幾組測試資料,第二行開始即為第一筆測試資料。每筆測試資料為一個正整數,數字的位數,最高有可能到 1000 位。輸出說明:對每一筆測試資料,輸出是否為 11 的倍數。是的話請輸出 1,反之則輸出 0。輸入範例:224841983960121輸出範例:01
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim fileContents As String fileContents = My.Computer.FileSystem.ReadAllText(Application.StartupPath & "\Test6.txt") Dim row() = Split(fileContents, vbNewLine) Dim result = "" For j As Integer = 1 To Val(row(0)) Dim str = row(j) Dim a = 0 For i As Integer = 1 To str.Length If (i 1) Mod 2 = 0 Then a = a Val(Mid(str, i, 1)) Else a = a - Val(Mid(str, i, 1)) End If Next Dim str1 = "" If a = 0 Or a = 11 Then str1 = "1" '是11的倍數 Else str1 = "0" End If result = result & str1 & vbNewLine Next My.Computer.FileSystem.WriteAllText(Application.StartupPath & "\result6.txt", result, False) End End Sub End Class
這題考慮到的問題是 最高有可能到 1000 位
是個天大的數字阿
所以並不能方式直接判斷 數字 MOD 11 = 0
當然
要是這樣出題還需要考嗎
解決方法是
a = 奇數位數的數字相加
b = 偶數位數的數字相加
假若a - b = 0 或者 11 就是11的倍數
2022年12月08日 22:28
It is much appreciated that you Shared the program to Determine whether it is a multiple of 11 with the source code to real estate agent Welder make it easier to understand. It is very helpful, and it is a great example for others Who Might be trying to learn how to code.
2022年12月29日 15:18
We much appreciate you sharing the source code for the programme to check if a number is a multiple of 11, which makes it easier to understand. engagement rings It is quite beneficial and serves as a fantastic model for those who might be attempting to learn how to code.