ここで質問するのか、数学のサイトで質問するのかわかりませんが、ここで試してみます。割り当ては次のとおりです。ユーザーは、ドメインDである10個の数字を入力します。ステートメントを評価する必要があります:
For All x, y in D, x<y or y <2x
。私の質問、xとは何ですか?yとは何ですか?ドメインがx=1、y = 2などであるため、1 2 3 4 5 6 7 8 9 10と入力すると、1<2かどうかを確認しますか|| 2 <2(1)?
'x'のみを使用したが、入力された10個の数値(xとy)からは何の手がかりもない他の3つのステートメントをコーディングしました。また、ユーザーがaxとyを10個の整数だけ入力する必要はありません。
私が行った他のステートメントのコードを投稿します。
using std::cout;
using std::cin;
void ASearch(int arr[], int);
void BSearch(int array[], int size);
void CSearch(int array[], int size);
int main(int argc, const char * argv[])
{
const int SIZE = 10;
int NumArray[10];
int num = 0;
int count = 0;
while (count < 10)
{
cout << "Enter Number "<< count + 1 <<": ";
cin >> NumArray[count];
++count;
}
/*if(!isdigit(num))
{
for (int i = 0; i < 9; ++i)
{
cout << "Enter Number "<< i + 2 <<": ";
cin >> NumArray[i];
}
}else cout << "Error: numbers only";*/
for(int j = 0; j < SIZE; ++j)
{
cout << " " << NumArray[j];
}
ASearch(NumArray, SIZE);
BSearch(NumArray, SIZE);
CSearch(NumArray, SIZE);
return 0;
}
void ASearch(int arr[], int size)
{
int pos = 0;
int on = -1;
int oddTrue = 0;
int oddFalse = 0;
while (on == -1 && pos < size)
{
cout << " \nchecking: " << arr[pos];
if (arr[pos] % 2 != 0 && arr[pos] > 0)
{
cout <<"\nTrue: " <<arr[pos] << " is > 0 and odd";
++oddTrue;
}
else if(arr[pos] % 2 != 0 && arr[pos] < 0)
{
cout <<"\nFalse" << arr[pos] << "is < 0 and odd";
++oddFalse;
}
else cout << "\nNumber is even";
++pos;
}
if (oddFalse > 0) cout<< "\n>>>>>>>>>A is FALSE";else cout <<"\n>>>>>>A IS TRUE";
return;
}
void BSearch(int array[], int size)
{
int on = -1;
int pos = 0;
int count = 0;
while(on == -1 && pos < size)
{
cout << "\n checking "<<array[pos];
if(array[pos] % 2 != 0 && array[pos] > 10)
{
cout << "\nTrue: " << array[pos] <<" is > 10 & odd";
++count;
}else
{
cout <<"\nFalse";
--count;
}
++pos;
}
if(count > 1 ) cout << "\n>>>>>>>>>>B IS TRUE"; else cout <<"\n>>>>>>>>>B IS FALSE";
return;
}
void CSearch(int array[], int size)
{
int pos = 0;
int on = -1;
int TrueCount = 0;
int FalseCount = 0;
while (on == -1 && pos < size)
{
cout << "\n checking "<<array[pos];
if(array[pos] % 2 == 0 || array[pos] % 3 == 0)
{
cout << "\nTrue: " << array[pos] <<" is divisible by 2 or 3";
++TrueCount;
}
else if(array[pos] % 2 != 0 || array[pos] % 3 != 0)
{
cout <<"\nFalse";
++FalseCount;
}
++pos;
}
if (TrueCount < 10)
cout << "\n>>>>C is FALSE"; else cout << "\n>>>>>>>>>>C is TRUE";
}