Following C program first ask to the user to enter the array
size then it will ask to enter the array elements, then it will finally ask to
enter a number or element to be search in the given array to check whether it
is present in the array or not, if it is present then at which position :
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int array[10], i, num, n, count=0, position;
printf("Enter the array size : ");
scanf("%d",&n);
printf("Enter Array Elements : ");
for(i=0; i<n; i++)
{
scanf("%d",&array[i]);
}
printf("Enter the number to be search : ");
scanf("%d",&num);
for(i=0; i<n; i++)
{
if(array[i]==num)
{
count=1;
position=i+1;
break;
}
}
if(count==0)
{
printf("Number not found..!!");
}
else
{
printf("%d found at position %d",num, position);
}
getch();
}
#include<conio.h>
void main()
{
clrscr();
int array[10], i, num, n, count=0, position;
printf("Enter the array size : ");
scanf("%d",&n);
printf("Enter Array Elements : ");
for(i=0; i<n; i++)
{
scanf("%d",&array[i]);
}
printf("Enter the number to be search : ");
scanf("%d",&num);
for(i=0; i<n; i++)
{
if(array[i]==num)
{
count=1;
position=i+1;
break;
}
}
if(count==0)
{
printf("Number not found..!!");
}
else
{
printf("%d found at position %d",num, position);
}
getch();
}
Run1:
Run2:
Previous Next
No comments:
Post a Comment