私の課題では、プログラムのユーザーにいくつかの数値を入力するように依頼し、「5 で割り切れる範囲 [11, 131] の数値の量は...」などの特定の質問に回答する必要があります。この瞬間まで、私のプログラムは数字の量を提供しますが、具体的にはどの数字がその質問に対する答えであるかをユーザーに伝えたいです。私のコードは次のとおりです。
int[] userInput = new int[10000];
int counter = 0;
int input10to75mod2 = 0;
int nums_17_103_sq_div_9 = 0;
int sum_17_103_sq_div9 = 0;
int max = 0;
int sum_of_sq = 0;
int nums_div_of_largest = 0;
int nums_div_of_sum_of_sq = 0;
Console.WriteLine ("Please type some numbers");
for (counter = 0; counter < userInput.Length; counter++) {
string input = Console.ReadLine ();
if (input == "" || input == "stop" || input == " ")
break;
else
int.TryParse (input, out userInput [counter]);
}
int sum = 0;
for (int i = 0; i < userInput.Length; i++) {
sum += userInput [i];
}
for (int j = 0; j < userInput.Length; j++) {
if (((userInput [j] % 2) == 0) && userInput [j] > 10 && userInput [j] < 75) {
input10to75mod2++;
}
//ARITHMETIC MEAN OF NUMBERS IN RANGE [17,103] WHICH HAVE THEIR SQUARE DIVISIBLE BY 9
if (userInput [j] >= 17 && userInput [j] <= 103 && ((userInput [j] * userInput [j]) % 9) == 0) {
nums_17_103_sq_div_9++;
sum_17_103_sq_div9 += userInput [j];
}
for (int r = 0; r < j; r++) {
if (userInput [r] > max) {
max = userInput [r];
}
if ((userInput [r] % max) == 0 && max != userInput [r]) {
nums_div_of_largest++;
}
}
}
int mean = 0;
int.Parse (mean.ToString ());
if (nums_17_103_sq_div_9 > 0) {
mean = sum_17_103_sq_div9 / nums_17_103_sq_div_9;
}
//CONCLUSIONS
Console.WriteLine ("Conclusion 1: " + input10to75mod2); //Amount of numbers in range [10,75] that are divisible by 9
Console.WriteLine ("Conclusion 2: " + sum); //Sum of all entered numbers
Console.WriteLine ("Conclusion 3: " + nums_17_103_sq_div_9 + " AND " + sum_17_103_sq_div9); //Amount of numbers in range [17,103] with their square divisible by 9 and their sum
Console.WriteLine ("Conclusion 4: " + mean); //Arithmetic mean of numbers in range [17,103] which have their square divisible by 9
Console.WriteLine ("Conclusion 5: " + nums_div_of_largest); //Numbers that are divisors of largest of the entered numbers
//Console.WriteLine ("Conclusion 6: " + nums_div_of_sum_of_sq); //Numbers that are divisors of sum of squares of entered numbers
Console.ReadLine ();
}
}
}