首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >离散数学到c++

离散数学到c++
EN

Stack Overflow用户
提问于 2013-03-24 23:49:58
回答 1查看 1.4K关注 0票数 0

我不确定我是该在这里还是在数学网站上提问,但我会在这里试一试。这是赋值:用户输入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\x\2 <2(1)吗?

我编写了另外三个语句,它们只使用'x‘,但不知道输入的十个数字,即x和y,它不要求用户输入x和y--只输入10个整数。

我会把我做过的其他声明的代码发出去。

代码语言:javascript
复制
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";

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-25 00:01:10

这意味着x和y都可以接受集合D中的每个值。

伪码:

代码语言:javascript
复制
for i = 1:10
   for j = 1:10
       x = D[i]
       y = D[j]
       test x < y OR y < 2 * x
   loop
loop
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15605573

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档