我是靠谱客的博主 甜甜小蜜蜂,这篇文章主要介绍在有序的数列中查找某数,若该数在此数列中,则输出它所在的位置,否则输出no found,现在分享给大家,希望可以做个参考。

#include<stdio.h>
#define N 10
void main()
{  int a[N];
   int num,i;
   char ch='n';
   printf("Input an array:n");
   for(i=0;i<N;i++)
  scanf("%d",&a[i]);
   printf("Output the array:n");
   for(i=0;i<N;i++)
  printf("%d ",a[i]);
   printf("n");
   printf("Input a number:n");
   scanf("%d",&num);
   printf("start findingn");
   for(i=0;i<N;i++)
  if(num==a[i])
  {  ch='Y';
     printf("%d is the %dth number in the arrayn",num,i+1);
  }
  if(ch=='n')
  printf("no foundn");
}

最后

以上就是甜甜小蜜蜂最近收集整理的关于在有序的数列中查找某数,若该数在此数列中,则输出它所在的位置,否则输出no found的全部内容,更多相关在有序的数列中查找某数,若该数在此数列中,则输出它所在的位置,否则输出no内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(47)

评论列表共有 0 条评论

立即
投稿
返回
顶部