How to write a C program to accept n number from user,store these numbers into an array & count the number of occurrences of each number in C Programming Language ?
Solution:
/*C program to accept n number from user,store these numbers into an array & count the no of occurrences of each number*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],n,i,j,count=0;
clrscr();
printf("\nEnter the n numbers:");
scanf("%d",&n);
printf("\nEnter the numbers: ");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("\nEnter the number to count the occurrences: ");
scanf("%d",&j);
for(i=0;i<n;i++)
{
if(j==a[i])
{
count++;
}
}
printf("\nThe no of occurrences of given number:%d",count);
getch();
}
//OUTPUT:
//Enter the n numbers:5
//Enter the numbers: 11
//12
//11
//11
//14
//Enter the number to count the occurrences: 11
//The no of occurrences of given number:3