Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过PPM在C中创建标志_C_Loops_If Statement_Printf_Ppm - Fatal编程技术网

通过PPM在C中创建标志

通过PPM在C中创建标志,c,loops,if-statement,printf,ppm,C,Loops,If Statement,Printf,Ppm,我试图通过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)); } e

我试图通过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));
   }
 }
}

出于某种原因,我的函数将编译。。。有人能帮我解决这个问题吗

阅读如何使用逻辑运算符
&&
|

不需要为“左红色、中白色、右红色”添加单独的检查,您可以假设您是用红色绘制的,只检查中间部分


既然你想用白色画画[x>0.3&&x 0.3&&y啊,非常感谢!!!我一直在尝试计算每个边框的比例,我在使用wikipedia….看起来我在使用它们的宽高比时有点走火了。在我的书中,他们一直使用我,所以我一直都在遵循我,但我完全理解你从何而来的y placem恩,再次感谢!“如果这能回答你的问题,你可以考虑接受它。”
void Pixel(int red, int green, int blue){
  printf("%i %i %i", red, green, blue);
}
if (x < width * .1 || y < height * .1 || x > width * .9 || y > height * .9)
  ..black..
else
  if ((x > width *.3 && x <= width * .4) || (y > height *.3 && y <= height * .4))
    ..white..
  else
    ..red..
printf("%i", Pixel(255,51,51));