Thursday, 21 June 2012

write a c program to accept n number from user store these number into an array & count the number of occurance of each number in the array element


/* write a c program to accept n number from user store these number
into an array & count the number of occurance of each number in the
array element*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10];
int i,j,n,count;
clrscr();
printf("\nhow many number :");
scanf("%d",&n);
printf("enter the element :");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\nthe occurance of number :\n");
for(i=0;i<n;i++)
{
count=0;
for(j=0;j<n;j++)
{
if(a[i]==a[j])
count++;
}
printf("\n%d=%d",a[i],count);
}
getch();
}
/*
how many number :5                                                            
enter the element :1 1 5 8 5                                                  
                                                                             
the occurance of number :                                                    
                                                                             
1=2                                                                          
1=2                                                                          
5=2                                                                          
8=1                                                                          
5=2                                                                          
*/

No comments: