Programming Tutorials

Write a Program in C to Find if a Number is Present in a List or not

Pinterest LinkedIn Tumblr
Here is a program in C to find if a number is present in a list of N numbers or not.

In this program for loop is used to search a number from the list of numbers and array of numbers is used to insert numbers in a list.

If the searched number is matched with any number in the list it throws to print it is presented in the list and if the searched number is not matched with any number in the list it throws to print it is not presented in the list.

C Program to Find if a Number is Present in a List

Read Also: C Program to Find the Sum and Average of Numbers Using Do-While Loop

Program in C to Find if a Number is Present in a List of N numbers or not

Use the following steps to find if a number is present in the list of N numbers or not.

Steps:

  1. At first declare integers i, n, m, and array of integers a[10].
  2. Print the message to enter how many elements want to insert and allow to insert.
  3. Print the message to enter the elements in the array.
  4. Use for loop to find out whether the given number is present in the list or not.
  5. Print the message on the screen whether the given number is present in the list or not.

Code:

#include<stdio.h>
#include<conio.h>

void main()
{
 int i,n,m,flag=0; int a[10];
 clrscr();

 printf("How many elements you want to enter n");
 scanf("%d",&n);

 printf("Enter element in the array n");
 for (i=0; i<n; i++)
 scanf("%d", &a[i]);

 printf("Enter the element you want to search n");
 scanf("%d", &m);

 for (i=0; i<n; i++)
  {
   if(a[i]==m)
   {
   flag=1;
   break;
   }
  }
 if(flag==0)
  printf("Not present");
 else
  printf("Present");
 getch();
}

Please follow and like us:
RSS
Follow by Email
X (Twitter)
Visit Us
Follow Me
YouTube
YouTube
LinkedIn
linkedIn | Write a Program in C to Find if a Number is Present in a List or not
Share

Author

Shuseel Baral is a web programmer and the founder of InfoTechSite has over 8 years of experience in software development, internet, SEO, blogging and marketing digital products and services is passionate about exceeding your expectations.

1 Comment

  1. rajdeojhabgp Reply

    IF show that c programing in come to managment time is very hard process a application , there are application in c to model int char_ file in storage _ computre file . if show that information to put down a some time to implemant a c programing

Write A Comment

RSS
Follow by Email
X (Twitter)
Visit Us
Follow Me
YouTube
YouTube
LinkedIn
Share