Wednesday, February 19, 2014

C Program for Searching an Element

with 0 Comment
#include<stdio.h>
#include<conio.h>
void main()
{
int a[50],i,j=0,n,x;
clrscr();
printf("\n\t Search an Element:\n");
printf("\n\t ************\n");
printf("Input:\n");
printf("****\n");
printf("\nEnter the no of numbers:\n");
scanf("%d",&n);
printf("\nEnter the Array of Elements:\n");
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
printf("\nEnter the no to be search:\n");
scanf("%d",&x);
for(i=1;i<=n;i++)
{
if(a[i]==x)
j++;
}
printf("\nOutput:\n");
printf("\n****\n");
if(j>0)
printf("The No %d is present %d times",x,j);
else
printf("The No %d is not present",x);
getch();
}

0 comments:

Post a Comment

Powered by Blogger.

Blog Archive