zoukankan      html  css  js  c++  java
  • 查询(c语言实现)

     1 /*
     2 *  Describe:这是一个简单的查询程序
     3 *  Date: 2013/12/7
     4 */
     5 #include <stdio.h>
     6 #include <stdlib.h>
     7 #define MAX     10
     8 
     9 int main()
    10 {
    11         int i;
    12         int n;
    13         int array[MAX];
    14         n = MAX;
    15 
    16         printf("请输入 %d 个数
    ", n);
    17         for (i = 0; i < MAX; i++) {
    18                 printf("第 %d 个数 :", i + 1);
    19                 scanf("%d", &array[i]);
    20                 if (i == MAX - 1)
    21                         printf("already completed input!
    ");
    22         }
    23 
    24         while (1) {
    25                 int key;
    26                 printf("输入欲查找的数,并回车:
    ");
    27                 scanf("%d", &key);
    28                 n = search(array, MAX, key);
    29                 printf("the number you entered locates in %d  
     ", n);
    30         }
    31         return 0;
    32 }
    33 
    34 int search(int *array, int n, int key)
    35 {
    36 
    37         while (array[n - 1] != key)
    38                 n--;
    39         return n;
    40 }
  • 相关阅读:
    jquery.md5
    LoginPasswordHelp
    RSA(非对称加密算法、公钥加密算法)
    Swiper 3.4.1
    layer web 弹窗
    操作系统
    查看命令帮助
    软件卸载
    重定向命令
    终端命令格式的组成
  • 原文地址:https://www.cnblogs.com/hare/p/3463218.html
Copyright © 2011-2022 走看看