C中的数字检查

C中的数字检查,c,C,(这意味着什么) 在处理“交易或不交易”项目时,我做了一个函数检查(); 要检查任何两个案例是否相同,如果相同,请更改其中一个,然后再次检查 函数deal为有奖案例设置随机数,然后调用check() #包括 #包括 #包括 无效交易(无效); 作废检查(作废); 国际案例[22]; 国际奖金[22]=1,2,3,4,5,6,8,10,15,20,25,35,50,65,85100105135165200250}; int main() {int a=0; 交易(); 虽然(a您就快到了,但有一个

(这意味着什么)

在处理“交易或不交易”项目时,我做了一个函数检查(); 要检查任何两个案例是否相同,如果相同,请更改其中一个,然后再次检查

函数deal为有奖案例设置随机数,然后调用check()

#包括
#包括
#包括
无效交易(无效);
作废检查(作废);
国际案例[22];
国际奖金[22]=1,2,3,4,5,6,8,10,15,20,25,35,50,65,85100105135165200250};
int main()
{int a=0;
交易();

虽然(a您就快到了,但有一个简单(且非常常见)的算法或对数组进行置乱。通过数组一次,您可以随机选择每个值的位置,而无需重复。由于置乱函数的操作,现在不必使用检查函数

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void deal(void);
void check(void);

int cases[22];
int prizes[22] = {1,2,3,4,5,6,8,10,15,20,25,35,50,65,85,100,105,135,165,200,250};

int main()
{
  srand(time(NULL));

  int a = 0;
  deal();

  for(a = 0 ; a < 22 ; a++)
    printf("%d \n", cases[a]);

  return 0;
}

//this is a neat algorithm for re-ordering an array without duplication
void scramble(int* array, int length)
{
  int i;
  int r;
  int temp;

  for(i = 0 ; i < length ; i++)
  {
    //swap this element with a random one to it's left (or itself)
    r = rand() % (i + 1);

    temp = array[r];
    array[r] = array[i];
    array[i] = temp;
  }
}

void deal(void)
{
  int r;
  int n = 1;

  //copy the prizes across directly
  for(n = 0 ; n < 22 ; n++)
    cases[n] = prizes[n];

  scramble(cases, 22);
}
#包括
#包括
#包括
无效交易(无效);
作废检查(作废);
国际案例[22];
国际奖品[22]={1,2,3,4,5,6,8,10,15,20,25,35,50,65,85100105135165200250};
int main()
{
srand(时间(空));
int a=0;
交易();
对于(a=0;a<22;a++)
printf(“%d\n”,案例[a]);
返回0;
}
//这是一个整洁的算法,可以在不重复的情况下对阵列重新排序
无效置乱(整数*数组,整数长度)
{
int i;
INTR;
内部温度;
对于(i=0;i
详细检查scramble()函数,您会发现它非常有趣


根据评论中的建议进行编辑,将算法更改为单程。

您的问题是什么?如何将每个选项中的一个打印出来。
(n他的错误在哪里?你的答案是如何解决的?我看到的只是一个全新的程序,而不是对他的解决方案的简单修复。为了他的学习,指出错误,只有修复错误会更好。这是一个非常糟糕的回答方式。我同意@PaulOgilvie的观点,你应该解释你写的东西。-有时我希望有一个更好的答案“另存为草稿”按钮。很抱歉出现了半个帖子。如果您允许自己交换一个数字,您只需要一次即可。@KlasLindbäck,很好的观点,编辑以反映这一点。
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void deal(void);
void check(void);

int cases[22];
int prizes[22] = {1,2,3,4,5,6,8,10,15,20,25,35,50,65,85,100,105,135,165,200,250};

int main()
{
  srand(time(NULL));

  int a = 0;
  deal();

  for(a = 0 ; a < 22 ; a++)
    printf("%d \n", cases[a]);

  return 0;
}

//this is a neat algorithm for re-ordering an array without duplication
void scramble(int* array, int length)
{
  int i;
  int r;
  int temp;

  for(i = 0 ; i < length ; i++)
  {
    //swap this element with a random one to it's left (or itself)
    r = rand() % (i + 1);

    temp = array[r];
    array[r] = array[i];
    array[i] = temp;
  }
}

void deal(void)
{
  int r;
  int n = 1;

  //copy the prizes across directly
  for(n = 0 ; n < 22 ; n++)
    cases[n] = prizes[n];

  scramble(cases, 22);
}