Write a Program in C to Find if a Number is Present in a List or not
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.
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:
- 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();
}
Related Posts:
- Write a Program in C to Copy a String to Another.
- Write a Program in C to Sort a List of Numbers in Ascending Order
- Write a Program in C to Calculate the Factorial Value of an Integer.
- Write a Program in C to Determine Whether a Number is Prime or Not.
- C Program to Find the Sum and Average of Numbers Using Do-While Loop
- C Program to Read Set of Real Numbers from Keyboard & Find the Maximum
- How to Create a Digital Clock in JavaScript?
- How to Detect Visitor's Browser Using JavaScript?
- How to Create JavaScript Image Slideshow with Links
- Simple JavaScript Fade Effect Animation Using Jquery
- How to Create Simple JavaScript Fade Effect Animation?
Write a Program in C to Find if a Number is Present in a List or not
Reviewed by mohamed
on
8:46 ص
Rating:
ليست هناك تعليقات: