求教!一个简单计算程序,如何修改程序?
a的取值范围是0-9,约束条件是:
0<=a<=t1[i]+2;
0<=a<=t1[i]-2;
0<=fabs(a-b)<=t2[i]+2;
0<=fabs(a-b)<=t2[i]-2;
0<=fabs(fabs(a-b)-fabs(b-c))<=t1[i]+2;
0<=fabs(fabs(a-b)-fabs(b-c))<=t1[i]-2;
如何计算出符合约束条件的a的值?
#include<stdio.h>
#include<math.h>
void main()
{
int
b=1,
c=6;
int a,i,j,k;
int t1[4]={2,3,4,5 },
t2[4]={ 1,3,4,8 },
t3[2]={6,7 };
for(a=0;a<10;a++)
{
for(i=0;i<4 ;i++)
0<=a<=t1[i]+2;
0<=a<=t1[i]-2;
for(j=0;j<4 ;j++)
0<=fabs(a-b)<=t2[i]+2;
0<=fabs(a-b)<=t2[i]-2;
for(k=0;k<2 ;k++)
0<=fabs(fabs(a-b)-fabs(b-c))<=t3[i]+2;
0<=fabs(fabs(a-b)-fabs(b-c))<=t3[i]-2;
printf("%d ",a);
}
}
[此贴子已经被作者于2017-4-11 17:49编辑过]