20_10

Write a C code to find the number of times a particular element (num) exist in an array.

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;

}

Output:
C code to find the number of times a particular element exist in an array


No comments:

Post a Comment

Write a program in C to convert a decimal number to binary using recursion.

 Source code: //Write a program in C to convert a decimal number to binary using recursion. #include<stdio.h> long convertB_to_D(int d...