Wednesday, 8 January 2014

C Program Accept 10 numbers and no. to search, print its occurrence Using Array

/* Accept 10 numbers and no. to search, print its occurence
 Write a program to accept 10 no’s  and a number to search and print how many times it occurs in array */

# include<stdio.h>
# include<conio.h>

void main()
{
 int arr[10];
 int i,cnt=0,tosearch;
 clrscr();
 /* accepting an array*/
 for(i=0;i<10;i++)
  {
   printf("\n Enter %d number-",i);
   scanf("%d",&arr[i]);
   }
 printf("\nEnter a number to be search-");
 scanf("%d",&tosearch);
 for(i=0;i<10;i++)
 {
  if(arr[i]==tosearch)
    cnt++;
 }
 printf("\n Number occurs %d times",cnt);
 getch();
}

No comments:

Post a Comment