C++问题,在线高分求解

来源:百度知道 编辑:UC知道 时间:2024/09/28 11:14:20
main( )
{
int cocks,hens,chicks;
cocks=0;
while(cocks<=19)
{
hens=0;
while(hens<=33)
{
chicks=100-cocks-hens;
if(5*cocks+3*hens+chicks/3==100&&chicks%3==0)
printf("%d,%d,%d\n",cocks,hens,chicks);
hens=hens+1;
}
cocks=cocks+1;
}
}
错误
C:\Documents and Settings\Owner\bianqian.cpp(12) : error C2065: 'printf' : undeclared identifier

"printf"undeclared identifier
是因为程序开头需要加#include<stdio.h>
stdio.h是标准输入输出流的意思

改成下面这个就可以了
#include<iostream>
void main( )
{
int cocks,hens,chicks;
cocks=0;
while(cocks<=19)
{
hens=0;
while(hens<=33)
{
chicks=100-cocks-hens;
if(5*cocks+3*hens+chicks/3==100&&chicks%3==0)
printf("%d,%d,%d\n",cocks,hens,chicks);
hens=hens+1;
}
cocks=cocks+1;
}
}

运行结果
0,25,75
4,18,78
8,11,81
12,4,84

包含头文件。

加头文件#include<stdio.h>