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.
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
Steps:
- At first declare integers i, n, m, and array of integers a[10].
- Print the message to enter how many elements want to insert and allow to insert.
- Print the message to enter the elements in the array.
- Use for loop to find out whether the given number is present in the list or not.
- 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();
}
1 Comment
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