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


C Program to Find if a Number is Present in a List
Here is a C program 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.







 A C Program to Find if a Number is Present in a 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();
}




Related Posts:



شاب أردني عمري 16 سنة أحب كل جديد في عالم الانترنت من مواقع وبرامج واحب التدوين ودائما ابحث عن الجديد لتطوير مهاراتي في مختلف الميادين التي تعجبني لكي انقل لكم وانا مدون واعمل فى مجال التدوين منذ فترة واحب معرفة الجديد والتعرف على الصدقاء .

شارك المقالة

مقالات ذات صلة