Array 2- 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

Related Post

Array:
String functions:
General (Loops-for/while)
Write a Program to print reverse of a given number Write a Program to print Product of Digits (eg. 212=2*1*2=4) of a given number Write a C++ Program to Convert Binary into Decimal Number