C语言问题求大神指教
#include<stdio.h>#include<stdlib.h>#defineabc(c)if(c>'Z')c='A'+(c-'Z')-1;if(c<'A')c='...
#include <stdio.h>
#include <stdlib.h>
#define abc(c) if(c>'Z') c='A'+(c-'Z')-1; if(c<'A') c='Z'-('A'-c)+1;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int s,t,A,B,C=303;
float i=1;
double x;
while(i<=6)
{x=7*303/((5.6)-(i));
t=x;
i+=1;
printf("%f\n",x);
if(t-x==0||x>0)
{s=t;
break;}
}
A=s/5;
B=s-A-C;
printf("sum=%d\n",s);
printf("A=%d\n",A);
printf("B=%d\n",B);
printf("C=%d\n",C);
return 0;
}
输出的s等于0,也就是if(t-x==0||x>0)的条件每一组x和t都不满足,但是在我输出的x和t中确实又满足条件的一组,为什么? 展开
#include <stdlib.h>
#define abc(c) if(c>'Z') c='A'+(c-'Z')-1; if(c<'A') c='Z'-('A'-c)+1;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int s,t,A,B,C=303;
float i=1;
double x;
while(i<=6)
{x=7*303/((5.6)-(i));
t=x;
i+=1;
printf("%f\n",x);
if(t-x==0||x>0)
{s=t;
break;}
}
A=s/5;
B=s-A-C;
printf("sum=%d\n",s);
printf("A=%d\n",A);
printf("B=%d\n",B);
printf("C=%d\n",C);
return 0;
}
输出的s等于0,也就是if(t-x==0||x>0)的条件每一组x和t都不满足,但是在我输出的x和t中确实又满足条件的一组,为什么? 展开
1个回答
展开全部
#include <stdio.h>
#include <stdlib.h>
#define abc(c) (if(c>'Z') c='A'+(c-'Z')-1; if(c<'A') c='Z'-('A'-c)+1;)
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
double A,B,C=303;
float i=1;
double s,t,x;
while(i<=6)
{
x=7*303/((5.6)-(i));
t=x;
i+=1;
printf("%lf\n",x);
if(( t-x>-0.0000001 && t-x< 0.000001 )||x>0)
{
s=t;printf("%lf\n",s);
break;
}
}
A=s/5;
B=s-A-C;
printf("sum=%lf\n",s);
printf("A=%lf\n",A);
printf("B=%lf\n",B);
printf("C=%lf\n",C);
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询