Question: I would like to implement this C code below for the K-means clustering algorithm. However, instead of creating 2 clusters, I want to create 4

I would like to implement this C code below for the K-means clustering algorithm. However, instead of creating 2 clusters, I want to create 4 clusters. Can someone help me with this? The initial code in C programming (Not C++) is below:

#include

int main() { int i1,i2,i3,t1,t2;

int k0[10]; int k1[10]; int k2[10];

printf(" Enter 10 numbers: "); for(i1=0;i1<10;i1++) { scanf("%d",&k0[i1]); }

//initial means int m1; int m2;

printf(" Enter initial mean 1:"); scanf("%d",&m1); printf(" Enter initial mean 2:"); scanf("%d",&m2);

int om1,om2; //old means

do {

//saving old means om1=m1; om2=m2;

//creating clusters i1=i2=i3=0; for(i1=0;i1<10;i1++) { //calculating distance to means t1=k0[i1]-m1; if(t1<0){t1=-t1;}

t2=k0[i1]-m2; if(t2<0){t2=-t2;}

if(t1

}

t2=0; //calculating new mean for(t1=0;t1

t2=0; for(t1=0;t1

//printing clusters printf(" Cluster 1:"); for(t1=0;t1

printf(" Cluster 2:"); for(t1=0;t1

printf(" ----"); }while(m1!=om1&&m2!=om2);

printf(" Clusters created");

//ending

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!