This is a try to put the solutions of each possible problem related to C and C++. You can find here C basic lab, C++ basic Lab, Data Structure Lab, DAA Lab, Operating System Lab, Graphics Lab, Compiler Lab, Network Lab, and other problems.
Saturday, 9 March 2013
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:\n");
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\t",b[j]);
printf("times: %d\n",c[j]);
}
getch();
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
You are welcome, your comment helps me to make this blog more better.