Q. Write a program using pointer to search a given element in array of size N.
BIT-C Programming-2019-GroupB-10No-8 Marks-Solution
#include<stdio.h>
int main()
{
int size,num,i,a[15],*p,flag=0;
printf("Enter the size of array: ");
scanf("%d",&size);
printf("Enter %d elements:",size);
for ( i = 0; i < size; i++)
{
scanf("%d",&a[i]);
}
printf("Enter number to search: ");
scanf("%d",&num);
p=a;
for ( i = 0; i < size; i++)
{
if(*p==num)
{
flag=1;
break;
}
p++;
}
if(flag==1)
{
printf("Number is present in array");
}
else
{
printf("Number is not present in array");
}
return 0;
}
Output:
If you are using Turbo C++ IDE, then use conio.h in link section after stdio.h
and use getch(); to hold the output screen, just before the end of main function.
If you have any confusion regarding the program, please, comment below.
Happy Coding !
Thank you
Search a given element in array of size n using pointer - C
11:16 PM
C Programs
,
OldQuestionSoluton2019C
,
pointer and array
,
pointer in c
,
Searching an element in array
,
searching using pointer
Edit
0 comments:
Post a Comment