gpt4 book ai didi

c++ - 离散数学到 C++

转载 作者:行者123 更新时间:2023-11-28 03:20:22 25 4
gpt4 key购买 nike

我不确定我应该在这里还是在数学网站上提问,但我会在这里试一试。分配如下:用户输入 10 个数字,即域 D。我需要评估声明: For All x, y in D, x<y or y <2x 。我的问题是,x 是什么,y 是什么?如果我输入 1 2 3 4 5 6 7 8 9 10 作为域 x =1,y =2 等等?我是否检查 1 < 2 || 2 <2(1)?

我编写了另外三个仅使用“x”但不知道输入的十个数字中哪个是 x 哪个是 y 的语句。而且它不要求用户输入 x 和 y 只是十个整数。

我将发布我所做的其他语句的代码。

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";

}

最佳答案

意思是x和y都可以取集合D中的每一个值。

在伪代码中:

for i = 1:10
for j = 1:10
x = D[i]
y = D[j]
test x < y OR y < 2 * x
loop
loop

关于c++ - 离散数学到 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15605573/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com