【发布时间】:2013-11-15 05:57:52
【问题描述】:
我正在尝试通过 PPM 在 C 中设计丹麦国旗,但我似乎无法让我的功能正常工作,因为我想找到一种更有效的方法将所有地方循环在一起,而不是全部执行 if /else if 语句。
for(i=0; i < height; i++){
for(x=0; x < width; x++){
if(x <= width *.3 && i <= height * .3)
{
printf("%i", Pixel(255,51,51));
}
else if(x<= width * .1 && i <= height *.1)
{
printf("%i",Pixel(0,0,0));
}
else if(x <= width * .405 && i <= height *.3)
{
printf("%i", Pixel(255,51,51));
}
else if(x <= width * .4 && i <= height)
{
printf("%i", Pixel(0,0,0));
}
else
{
printf("%i", Pixel(255,51,51));
}
}
}
这是我的身体,我不知道如何将它循环在一起,而不是创建大量的 if/else 语句,而这一半时间可能不起作用....
void Pixel(int red, int green, int blue){
printf("%i %i %i", red, green, blue);
}
另外由于某种原因,我的函数会编译...有人也可以帮助我解决这个问题吗?
【问题讨论】:
标签: c loops if-statement printf ppm