In this article we learn c
program to search element in an array. In this program we use 1-D array (it’s
obvious) and also use loop, in this program we use for loop and write our
program.
Before we write our program,
you need to know about
- ·
Loop (in this program
we use ‘for’ loop)
- ·
Array
- ·
if-else keyword (and
it’s uses)
- ·
relational operator
now we talk about our program,
so in this program we take 10 input from user using 1-D array and take another
input for searching now for more clarity we write a program and take a look of
output.
Now we write our program c program to search element in an array.
SOURCE CODE:-
#include<stdio.h>int main(){ int a[10],i,n,p=0; printf("enter the all the numbers:"); for(i=0;i<10;i++){ scanf("%d",&a[i]); } printf("enter number to search:"); scanf("%d",&n); for(i=0;i<10;i++){ if(n==a[i]){ p=1; } } if(p==1){ printf("%d is exist",n); } else{ printf("%d is not exist",n); } return 0;}
OUTPUT-1:-
enter the all the numbers:45
23
67
34
22
32
44
78
12
11
enter number to search:67
67 is exist
OUTPUT-2:-
enter the all the numbers:10
15
8
2
78
18
28
79
18
35
enter number to search:30
30 is not exist
1 Comments
Through this post, I know that your good knowledge in playing with all the pieces was very helpful. I notify that this is the first place where I find issues I've been searching for. You have a clever yet attractive way of writing. finally some good food
ReplyDelete