FY_BCA_C_SLIP 9_2



Slip no - 9_2 Accept n number from user and store into array and count number of occurances of each element
#include<conio.h>
#include<stdio.h>

main()
{
int a[20],b[20],n,i,j,k,flag,cnt; printf("\n enter how many elemnets : "); scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter element : "); scanf("%d",&a[i]);
}

k=0;
for(i=0;i<n;i++) { flag=0;

for(j=0;j<k;j++)
{
if(a[i]==b[j])
{flag=1;
break;}
}
if(flag==0)
{
b[k]=a[i];
k++;
}
}
printf("\n Given array is : ");

for(i=0;i<n;i++)
{

printf("%d\t",a[i]);
}
printf("\n After removing duplicate element : "); for(i=0;i<k;i++)
{
printf("%d\t",b[i]);
}

for(i=0;i<k;i++) { cnt=0;
for(j=0;j<n;j++)
{
if(b[i]==a[j])
cnt++;
}
printf("\n %d occures %d times ",b[i],cnt);
}
getch();
}


No comments:

Post a Comment