gpt4 book ai didi

c - 找到一个子数组的最小值,而该值可能只有 1 或 2 或 3

转载 作者:太空宇宙 更新时间:2023-11-04 03:48:12 24 4
gpt4 key购买 nike

I have a problem使用以下代码:

#include<stdio.h>
main()
{
int len,no,n,a,result;
int start[100],end[100];
int width[100];

printf("enter the lenghth of the road : \n");
scanf("%d",&len);

printf("enter the width of the road ,in unitwise format for the given length : \n");
for(n=0;n<len;n++)
scanf("%d",&width[n]);

printf("enter the no of testcases : \n");
scanf("%d",&no);

printf("for each testcase enter the starting and end point : \n");
for(n=1;n<=no;n++){
printf("for testcase %d enter the start and end point respectively",n);
scanf("%d %d",&start[n],&end[n]);}

for(n=1;n<=no;n++){
for(a=start[n];a<=end[n];a++){
result=3;
if(width[a]<result)
result=width[a];
}

printf("for testcase %d the vehicle that can be used is %d",n,result);
printf("\n");}
}

虽然我觉得我在寻找最小宽度时应用了正确的逻辑,但我没有得到正确的结果。这个逻辑有什么问题?

最佳答案

放这条线

result=3;

在你的循环之前。

关于c - 找到一个子数组的最小值,而该值可能只有 1 或 2 或 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22764586/

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