Friday, September 30, 2011

Program To search a number in a set of numbers using C


#include<stdio.h>
#include<conio.h>
void main()
{
int  i,n,count=0;
float num[50],search;
clrscr();
printf("how many numbers ?");
scanf("%d",&n);
if(n<=0)
printf("invalid data");
else
{
for(i=0;i<n;i++)
{
printf("Enter the number-%d:",i+1);
scanf("%f",&num[i]);
}
printf("\n\n\nNumber to searched ? ");
scanf("%f",&search);
clrscr();

printf("\nThe number you entered are:\n");
for(i=0;i<n;i++)
printf("%g \t",num[i]);
printf("\n\n\n");
for(i=0;i<n;i++)
if(num[i]==search)
{
printf("Location-%d\n",i);
count++;
}
if(count)
printf("\nThe number %g exists in %d locations shown above",search,count);
else
printf("\nThe number %g does not exists in the set",search);
}
getch();
}

1 comments: