Monday, 6 January 2014

A PROGRAM TO SEARCH A NUMBER FROM ARRAY AND TO SHOW HOW MANY TIMES IT APPEARED....!!!!

#include<stdio.h>
# define size 15
void search(int arr[],int key );

int main()
{
    int array[15]={0};
    int x=0,key;
    printf("Enter the elements of array;");
    for(x=0;x<15;x++)
    {
       scanf("%d",&array[x]);
    }
    printf("Enter the number to be searched:");
    scanf("%d",&key);
   
    search(array,key);             
getch();
return 0;
}
void search(int arr[],int key)
{
     int x=0,count=0;
     for(x=0;x<size;x++)
     {
        if(key==arr[x])
        {
           count++;
        }
     }
     if (count>0)
     printf("The number was found %d times",count);
     else
     printf("The number was not found");
}

No comments:

Post a Comment