C program to find an element from Array

Simple C program to find an element from Array

Code:

#include<stdio.h>

#include<conio.h>



void main()

{

int a[20],i,x,n;

clrscr();

printf(“How many elements?”);

scanf(“%d”,&n);



printf(“Enter array elements:”);

for(i=0;i<n;++i)

scanf(“%d”,&a[i]);



printf(“nEnter element to search:”);

scanf(“%d”,&x);

for(i=0;i<n;++i)

if(a[i]==x)

break;



if(i<n)

printf(“Element found at index %d”,i);

else

printf(“Element not found”);



getch();

}

Comments

Popular posts from this blog

C program to evaluate Prefix Expression using Stack data structure

Java Program to Implement sorting algorithm using TCP on Server application

C++ program to perform data transformation Min-max and Z score Normalization