C Program to Check if a number is in an array[1000]

How to write a C Program to check if a number is in an array[1000] in C Programming Language ?

This C Program to Check if a number is in an array[1000].

Insert number for check.
If Number is found in the array[1000].
Else Number is not found in the array[1000].

Solution:

  1. #include <stdio.h>
  2. int check_number(double ar[1000],  double num);
  3. int main()
  4. {
  5.     double ar[1000], num;
  6.     int n ,i;
  7.     printf("n = ");
  8.     scanf("%d", &n);
  9.     printf("Insert Numbers : \n");
  10.     for(= 0 ; i < n ; i ++)
  11.     {
  12.         scanf("%lf", &ar[i]);
  13.     }
  14.     printf("Insert number for check : ");
  15.     scanf("%lf",&num);
  16.     if(1 == check_number(ar,num))
  17.     {
  18.         printf("Number is found in the array.\n");
  19.     }
  20.     else
  21.     {
  22.         printf("Number is not found in the array.\n");
  23.     }
  24.     return 0;
  25. }
  26. int check_number(double ar[1000], double num)
  27. {
  28.     int i;
  29.     for(= 0 ; ar[i] != '\0' ; i++)
  30.     {
  31.         if(num == ar[i])
  32.         {
  33.             return 1;
  34.         }
  35.     }
  36.     return 0;
  37. }


Learn More :