出于某种原因,当我尝试编译程序时,编译器表示权限被拒绝,Id返回1退出状态.谁能告诉我这意味着什么?谢谢
#include <stdio.h> /* Library inclusions */
#include "genlib.h"
#include "simpio.h"
int binSearch(int val, int numbers[], int size1); /* prototypes */
void sortArray (int numbers[], int size1);
int indexMax (int numbers[], int low, int high);
void swap (int numbers[], int loc, int loc1);
void getArray (int numbers[], int size1);
void displayArray (int numbers[], int size1);
main()
{
int value, size1;
printf("Enter the number of elements: ");
size1=GetInteger();
int numbers[size1];
getArray(numbers, size1);
sortArray(numbers, size1);
displayArray(numbers, size1);
printf("\nEnter value to find: "); …Run Code Online (Sandbox Code Playgroud) 我正在为C编写一个简单的Tic Tac Toe代码游戏.我已经完成了大部分代码,但我希望AI永远不会丢失.
我读过有关minimax算法的内容,但我不明白.如何使用此算法使计算机能够赢或赢但永不丢失?
我试图比较两种算法的运行时速度:一个强力C程序打印素数(10,000个数字)和一个Sieve of Eratosthenes C程序(也是10,000个素数).
我测得的筛选算法的运行时间为:0.744秒
我测得的蛮力算法的运行时间为:0.262秒
然而,有人告诉我,Eratosthenes算法的筛子比蛮力方法更有效,所以我认为它运行得更快.所以要么我错了,要么我的程序有缺陷(我怀疑).
因此,我的问题是:由于我得到了与我预期相反的结果,这是否证明了与试验师相比,Eratosthenes的Sieve 在速度方面确实是效率较低的算法?
我不确定它是否有任何意义,但我使用的是Dev C++编译器和Windows 7.
我想知道为什么这个节目的结果是5621?
#include <stdio.h>
main()
{
int i=56;
printf("%d\n",printf("%d",printf("%d",i)));
getch();
}
Run Code Online (Sandbox Code Playgroud) 这个程序要求我:编写一个与用户进行简单数字猜测的程序.用户想到一个数字,然后回答计算机询问的一系列问题,直到它正确猜出数字为止.
我的问题是编译器说:'arr'未声明(首次在此函数中使用)
到目前为止,这是我的代码:
#include <stdio.h>
#include "strlib.h"
#include "simpio.h"
#define size 200
int binSearch (int num);
void getArray (int arr[]);
main()
{
printf("Think of a number in the range of 1-200 and I'll guess it.\n");
int arr[size];
getArray(arr);
binSearch(arr);
getchar();
}
void getArray (int numbers[])
{
int number;
for(number=1;number>=200;number++)
{
arr[number]=number;
}
}
int binSearch(int num)
{
int low, high, mid;
string strReply;
low=0;
high=size-1;
while(low<=high);
{
mid=low+high/2;
printf("\nIs the number %d ?\t", mid);
strReply= GetLine();
if(StringEqual(strReply, "no")) …Run Code Online (Sandbox Code Playgroud) 我想知道在以下程序中导致分段错误的原因.我认为在递归过程中会发生分段错误.输入数字后,出现错误消息"发生访问分段错误".
这是代码:
#include <stdio.h>
#include "simpio.h"
int sum(int n);
main()
{
int n, Sum;
printf("Please enter the amount of elements in sequence n/n+1: ");
printf("LOL1\n");
n=GetInteger();
Sum=sum(n);
printf("LOL2\n");
printf("The sum of the first %d elements of the sequence n/n+1 is: %d", n, Sum);
printf("LOL3\n");
getchar();
}
int sum(int n)
{
if(n=0) return(0);
else return((sum(n-1))+(n/(n+1)));
}
Run Code Online (Sandbox Code Playgroud) c ×5
algorithm ×1
arrays ×1
function ×1
minimax ×1
performance ×1
primes ×1
recursion ×1
tic-tac-toe ×1