Monday, 22 July 2013

DWDM-Tutorial2

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
void main()
{
int i,j,k,r,count,r1,c;
int **b; //Binary dataset
float fr;
clrscr();
// initializing the dataset , having 10 rows and 5 collums

b=(int**)malloc(10*sizeof(int));

    for(i=1;i<=10;i++)
    {
        b[i]=(int*)malloc(5*sizeof(int));
    }

//after init dataset , FILLING it with zero (0)
    for(i=1;i<=10;i++)
    {
        for (j=1;j<=5;j++)
        {
            b[i][j]=0;
        }
    }


    for(i=1;i<=10;i++)
    {
    //random value for how many ITEMs in each transaction .

        r1=rand()%10;

        for(k=1;k<=r1;k++)
        {
        // randomly getting the items those are purched .
            r=rand()%11;
                    // mark apropriat item with 1
                    // rest of the items remain 0
            b[i][r]=1;

        }
    }
// This block used when you want to di spl a y the whole da t a s e t
    for(i=1;i<=10;i++)
    {
        for(j=1;j<=5;j++)
        {
            printf("%d",b[i][j]);
        }
            printf("nn");
    }


    for(i=1;i<=5;i++)
    {
        count=0; // initalizing counter
        for(j=1;j<=10;j++)
        {
            if(b[j][i]==1)
            {
                // increment if item found in transaction
            count++;
            }
        }
            // calculate the frequency of that item
        fr=5*count/10;
        printf("[%d]=%d frequency[%f] \n" ,i,count,fr) ;
    }
         getch() ;
}

No comments:

Post a Comment