编写一个for循环,打印整数1到40,用空格或换行符分隔。只能使用一个已声明为整数的变量count。
所以我用..。
for(count = 1; count <= 40; count++)
{
cout << " " << count;
}但它们使用stdio.h作为唯一的标头,并且无法识别cout。它提示输出格式应该是(“",count),但我不知道要使用哪个打印函数。stdio.h可以使用fprintf或fwrite,但是我没有足够的参数来执行这两个函数。有什么想法吗?
发布于 2010-12-31 14:45:03
您可以使用printf():
int count;
for (count=1; count<=40; count++)
{
printf("%d ", count);
}更多信息请点击这里:http://www.cplusplus.com/reference/clibrary/cstdio/printf/
发布于 2010-12-31 16:15:28
你可以在最后一项作弊,这样它就不会有尾随空格/换行符/逗号等……
int count;
for( count = 1; count <= 39; count++ )
{
printf( "%d ", count );
}
printf( "%d\n", ++count );如果这是家庭作业,忽略我的答案,自己解决吧!:)
发布于 2014-03-26 11:58:28
你想得太多了,试试这个吧。
for (count = 1; count <= 40; count++)
{
cout << count << endl;
}https://stackoverflow.com/questions/4568576
复制相似问题