该代码不适用于测试用例17 13 3 15。在我尝试过的其他测试案例中,它运行良好。
#include <stdio.h>
int max_of_four(int a,int b,int c,int d)
{
int max;
a=max;
if(b>max)
max=b;
if(c>max)
max=c;
if(d>max)
max=d;
return max;
}
int main() {
int a, b, c, d;
scanf("%d %d %d %d", &a, &b, &c, &d);
int ans = max_of_four(a, b, c, d);
printf("%d", ans);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 这是一个二进制搜索程序。但是,如果我将排序后的数组作为输入,程序将始终显示NOT FOUND作为输出。
我是初学者,所以我尝试删除了if语句
void binary(int [],int,int,int);
void main()
{
int i,a[100],n,beg,end,val;
printf("enetr the size :\n");
scanf("%d",&n);
printf("enter the elements :\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("enter the value to be search");
scanf("%d",&val);
beg=0;
end=n-1;
binary(a,beg,end,val);
}
void binary(int a[],int end,int beg,int value)
{
int i,mid,count=0;
while(beg<=end)
{
mid=((beg+end)/2);
if(a[mid]==value)
{
printf("the value is find at the %d position ",mid);
count=1;
}
if(value<a[mid])
end=mid-1;
else
beg=mid+1;
}
if(count==0)
printf("NOT FOUND");
}
Run Code Online (Sandbox Code Playgroud)
尽管有输入,但将输出显示为NOT FOUND
c ×2