用两个for语句
#include<stdio.h>
void main()
{ int a,b,c;
for( a=0;a<=19;a++)
{for(b=0;b<=33;b++)
{ c=100-a-b;
if(5*a+3*b+ c/3==100 && c%3==0)
printf("%d,%d,% d\n" ,a,b,c);}
}
}
方寸之内,剖天下; 方坛之内,析自我;
第二个问题的解
#include <stdio.h>
void main()
{
int x1,x2,y1,y2,i,j;
printf("请输入两组坐标\n");
printf("x1=");scanf("%d",&x1);printf("y1=");scanf("%d",&y1);printf("\n");
printf("x2=");scanf("%d",&x2);printf("y2=");scanf("%d",&y2);
if(x1>=x2||y1>=y2||x1<0||y1<0)
return;
for(i=0;i<y1;i++){printf("\n");}
for(i=1;i<=(y2-y1);i++)
{
for(j=1;j<(x2-x1);j++){printf(" ");}
for(j=x2-x1;j<x2;j++){printf("*");}
printf("\n");
}
printf("\n");
printf("S=%d\n",(x2-x1)*(y2-y1));
printf("L=%d\n",2*(x2-x1+y2-y1));
return;
}
#include<stdio.h>
#include <conio.h>
main()
{
int g,m,x,i,j;
FILE *fp;
fp=fopen("sj.txt","w");
for(g=0;g<=20;g++)
for(m=0;m<=((100-5*g)/3);m++)
for(x=0;x<=(100-5*g-3*m)*3;x++)
{
if(g+m+x==100&&5*g+3*m+x/3==100&&x%3==0)
{
fprintf(fp,"g:%d ",g);
fprintf(fp,"m:%d ",m);
fprintf(fp,"x:%d\n",x);
}
}
fclose(fp);
printf("finished!");
getch();
}
这样好看多啦,打开文件自己看,对if改变条件,放在不同文本里,对比数据。。。。。