用c语言写出,数学算式3x+1/3*y=100,输出所有满足等式的整数。其中x,y小于100。

来源:百度知道 编辑:UC知道 时间:2024/05/09 15:58:38

#include <stdio.h>
void main()
{ int x,y;
for(x=1;x<34;x++)
for(y=3;y<=100;y++)
if(3*x+y/3=100)
printf("x=%d\ty=%d\n",x,y)
}

#include int main(){int x,y; for(x=0;x<=100;x++) {for(y=0;y<=100;y++) if(3x+y/3==100) printf("%d,%d\n",x,y);}} 用for循环就可以了

#include <stdio.h>
#include <math.h>
main()
{int x,y;
for(x=0;x<=100;x++)
for(y=0;y<=100;y++)
if(9*x+y==300)/*因为要求输出整数解,所以题目式子需要变为整数形式*/
printf("x=%d,y=%d\n",x,y);
getch();
}
测试输出有11组解。
x=23,y=93
x=24,y=84
x=25,y=75
x=26,y=66
x=27,y=57
x=28,y=48
x=29,y=39
x=30,y=30
x=31,y=21
x=32,y=12
x=33,y=3