Source code:
//Write a C code to find the number of times a particular element (num) exist in an array.
#include<stdio.h>
int main()
{
int j, array[5], num;
for(j=0;j<5;++j)
{
printf("Enter the value for %d: ",j);
scanf("%d",&array[j]);
}
printf("Enter the number to find : ");
scanf("%d", &num); /* the number to find */
int count=0; /*to store number of occurrence of the given num */
int i;
for(i = 0; i < 5; i++)
{
if(array[i]==num)
count= count+1;
}
printf("The number %d occurs %d times", num, count);
return 0;
}
No comments:
Post a Comment