Showing posts with label values. Show all posts
Showing posts with label values. Show all posts

Friday, April 11, 2014

Count reapetation number of unique values of an array Sort according higher occurance of values


/* A program to calculate no. of uniqe values of an array
implemented logic can be useful anywhere-
where we required count no. of same rate books in a library
e.g. 250$: 3books 300$: 4books 34$: 5books
Date: 9/3/2013 10:05pm
Author: Mangilal Saraswat */

#include<stdio.h>
#include<conio.h>
void main()
{
 clrscr();
 int i,j,k,done,a[10],b[10],c[10];
 i=0; j=0; k=0; done=0;

 printf("Enter array:
");

 for(i=0;i<10;i++)
 {
  scanf("%d",&a[i]);
  c[i]=0;
 }

 for(i=0; i<10; i++)
 {
  for(j=0;j<k;j++)
  {
   if(a[i]==b[j])
   {
    b[j]=a[i];
    c[j]=c[j]+1;
    done=1;
   }
  }
  if(done==0)
  {
   b[k]=a[i];
   c[k]=c[k]+1;
   k=k+1;
  }
  done=0;
 }

 for(j=0;j<k;j++)
 {
  printf("value: %d ",b[j]);
  printf("times: %d
",c[j]);

 }
 getch();
}

Read More..
 
Blog Information - Powered By Blogger