科学出版社《运筹学》第二版决策论学了之后,自己作了个c程序,大家有兴趣看看,运行一下。 #include<stdio.h> #include<conio.h> #define M 10 int a[M][M],min[M],max[M],b[M],p[M][M],ma; float mp,mid[M],aver[M];
void main( ) { int m,n,i,j,choice,result,t; float c; clrscr( ); printf("It is strongly recommended that you read these items before you do your work.\n"); printf("1. This is a program for operations research.\n"); printf("2. You should read your textbooks to review the principles.\n"); printf("3. There are some defects in this program.\n"); printf(" If any,please send messages to the creator.\n"); printf("4. Copyright 2005-5-12 Zhang Zujin.\n"); printf(" QQ:283421560 E-mail:zhangzujin360732@163.com\n\n"); printf("Input m(fang an),n(zhuangtai):"); scanf("%d,%d",&m,&n); printf("Input shouyi juzheng(m*n):\n"); for(i=0;i<m;i++) for(j=0;j<n;j++) scanf("%d",&a[i][j]); printf("***********************Make a choice***********************\n"); printf("beiguan(1)--leiguan(2)--zhezhong(3)--dengkeneng(4)--yihan(5)\n"); scanf("%d",&choice);
if(choice==1) { for(i=0;i<m;i++) { min[i]=a[i][0]; for(j=1;j<n;j++) if(a[i][j]<min[i]) min[i]=a[i][j]; } result=1; ma=min[0]; for(i=0;i<m;i++) if(min[i]>ma) { result=i+1; ma=min[i]; } printf("Through caculating,the result is:\n"); for(i=0;i<m;i++) printf("%d\n",min[i]); printf("The result is:u(%d)=%d\n",result,ma); }
if(choice==2) { for(i=0;i<m;i++) { max[i]=a[i][0]; for(j=1;j<n;j++) if(a[i][j]>max[i]) max[i]=a[i][j]; } result=1; ma=max[0]; for(i=0;i<m;i++) if(max[i]>ma) { ma=max[i]; result=i+1; } printf("Through calculating,the result is:\n"); for(i=0;i<m;i++) printf("%d\n",max[i]); printf("The result is:u(%d)=%d\n",result,ma); }
if(choice==3) { printf("Input leguanxishu:"); scanf("%f",&c); if((c>=0)&&(c<=1)) { for(i=0;i<m;i++) { max[i]=a[i][0]; min[i]=a[i][0]; for(j=0;j<n;j++) { if(a[i][j]>max[i]) max[i]=a[i][j]; if(a[i][j]<min[i]) min[i]=a[i][j]; } mid[i]=c*max[i]+(1-c)*min[i]; } result=1; mp=mid[0]; for(i=0;i<m;i++) if(mid[i]>mp) { mp=mid[i]; result=i+1; } } else { printf("Error,the leguan xishu must be in [0,1]!\n"); return; } printf("Through calculating,the result is:\n"); for(i=0;i<m;i++) printf("%.2f\n",mid[i]); printf("The result is:u(%d)=%.2f\n",result,mp); }
if(choice==4) { for(i=0;i<m;i++) { aver[i]=0; for(j=0;j<n;j++) aver[i]+=(float)a[i][j]; aver[i]=aver[i]/n; } result=1; mp=aver[0]; for(i=1;i<m;i++) if(aver[i]>mp) { mp=aver[i]; result=i+1; } printf("Through calculating,the result is:\n"); for(i=0;i<m;i++) printf("%.2f\n",aver[i]); printf("The result is:u(%d)=%.2f\n",result,mp); }
if(choice==5) { for(j=0;j<n;j++) { b[j]=a[0][j]; for(i=1;i<m;i++) if(a[i][j]>b[j]) b[j]=a[i][j]; } for(j=0;j<n;j++) for(i=0;i<m;i++) p[i][j]=b[j]-a[i][j]; for(i=0;i<m;i++) { max[i]=p[i][0]; for(j=1;j<n;j++) if(p[i][j]>max[i]) max[i]=p[i][j]; } ma=max[0]; result=1; for(i=0;i<m;i++) if(max[i]<ma) { ma=max[i]; result=i+1; } printf("Through calculating,the result is:\n"); printf("***houhui juzhen******min***\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) printf("%4d",p[i][j]); printf("%8d",max[i]); printf("\n"); } printf("The result is:u(%d)=%d\n",result,ma); }
getch( ); }