Last active
September 24, 2016 17:22
-
-
Save axayjha/c044127510858624b57324160ddfcefe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| int diff(int a,int b) | |
| { | |
| int c=a-b; | |
| if(c>=0) | |
| return c; | |
| else | |
| return -c; | |
| } | |
| int main() | |
| { | |
| float grp_heads[100],n,matrix[100][100],min,dif,elements_in_row[100],m,p,temp=0,flag=1; | |
| float avg[100],sum[100]; | |
| int height,i,j,k,pos=0; | |
| printf("enter number of groups\n"); | |
| scanf("%d",&height); | |
| printf("enter the group heads:\n"); | |
| for(i=0;i<height;i++) | |
| scanf("%f",&grp_heads[i]); | |
| FILE *fp; | |
| fp=fopen("abc.txt","r"); | |
| if(!fp) | |
| return 1; | |
| for(i=0;i<100;i++) | |
| for(j=0;j<100;j++) | |
| fscanf(fp,"%f",&matrix[i][j]); | |
| for(i=0;i<height;i++) | |
| { | |
| elements_in_row[i]=1; | |
| sum[i]=grp_heads[i]; | |
| } | |
| for(i=0;i<100;i++) | |
| { | |
| for(j=0;j<100;j++) | |
| { | |
| min=diff(grp_heads[0],matrix[i][j]); | |
| pos=0; | |
| for(k=1;k<height;k++){ | |
| dif=diff(grp_heads[k],matrix[i][j]); | |
| if(min>dif){ | |
| min=dif; | |
| pos=k; | |
| } | |
| } | |
| elements_in_row[pos]++; | |
| sum[pos]=sum[pos]+matrix[i][j]; | |
| } | |
| } | |
| while(flag==1) | |
| { | |
| for(i=0;i<height;i++) | |
| { | |
| avg[i] = temp/elements_in_row[i]; | |
| temp = grp_heads[i]; | |
| if(avg[i]-grp_heads[i]<0.1) flag=0; | |
| else flag=1; | |
| grp_heads[i]=avg[i]; | |
| elements_in_row[i]=1; | |
| } | |
| if (flag==0) | |
| break; | |
| } | |
| for(i=0;i<height;i++) | |
| printf("%2f\n",grp_heads[i]); | |
| printf("\n"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment