打印出偶数
Print out even number
本文关键字:打印 更新时间:2023-10-16
我只是想在这里寻求你的帮助。我是 c++ 编程的新初学者。如何打印出 100 - 200 范围内的偶数。我尝试编写一些代码,但没有成功。这是我的代码。我希望,这里有人可以帮助我。将非常感激。谢谢。
include <stdio.h>
void main()
{
int i;
for (i= 100; i<= 200; i += 2){
print i;
}
}
嗯,很简单:
#include <iostream> // This is the C++ I/O header, has basic functions like output an input.
int main(){ // the main function is generally an int, not a void.
for(int i = 100; i <= 200; i+=2){ // for loop to advance by 2.
std::cout << i << std::endl; // print out the number and go to next line, std:: is a prefix used for functions in the std namespace.
} // End for loop
return 0; // Return int function
} // Close the int function, end of program
您使用的是 C 库,而不是C++库,也没有在 C++ 中调用print
的函数,也没有C
.也没有 void main 函数,请改用 int main()
。最后,您需要在 cout
和 endl
前面有std::
,因为它们位于 std
命名空间中。
使用以下代码:
#include <iostream>
int main()
{
int i;
for (i= 100; i<= 200; i += 2){
std::cout << i << std::endl;
}
return 0;
}
你的代码看起来不错。只需更改打印部分
#include <stdio.h>
int main()
{
for (int i= 100; i<= 200; i += 2){
printf("%d",i);
}
return 0;
}
这可能会有所帮助!
#include <iostream>
using namespace std;
int main()
{
for (int count = 100; count <= 200; count += 2)
{
cout << count << ", ";
}
cout << endl;
return 0;
}
相关文章:
- 如何循环打印顶点结构
- 为什么在popback()操作之后,它仍然打印完整的矢量
- 如何在c++中打印目录
- 有一个打印语句的函数是一种糟糕的编程实践吗
- 在线编译器中的分段C++没有打印消息
- 在C++中打印指向不同基元数据类型的指针的内存地址
- 这个指针和内存代码打印是什么?我不知道是打印垃圾还是如何打印我需要的值
- 如何将结构插入到集合中并打印集合的成员
- 在循环C++中指定字符串之后,不会打印该字符串
- 以螺旋方式打印矩阵的程序.(工作不好)
- 从控制台中删除最后打印的元素
- 如何使用Crypto++并为RSA返回可打印的字节/字符数组
- 如何仅使用对象名称打印特定于对象的成员
- 回溯C++不打印函数,因此文件
- 在一定长度后从数组中打印时缺少整数
- 为什么这个 c++ 代码打印出长度 5,当我打印出字符串时,程序会自动终止?
- 在gem5中打印文件中的所有cache_blocks
- 打印数字图案
- Log4cpp:以UTC/GMT时区打印日期
- 如何使用gdb制作一个可以漂亮地打印每个对象的C++函数