小编Jos*_*ama的帖子

c ++动态数值系列

我正在尝试创建一个程序,按照特定的数字系列条件(1-1-3-6-8-8-10-20)打印前200个元素,但不显示只有200个元素显示802.我假设是因为"for"循环中的代码,但我花了很多时间考虑如何减少代码到工作,我想不出别的.我很沮丧,需要你的帮助.

练习是在代码评论上

//Print the following numerical series 1-1-3-6-8-8-10-20  until 200
#include <stdafx.h>
#include <iostream>
#include <stdlib.h>
using namespace std;

int main()
{
    int Num1=200, z = 0, x = 1, y = 1;

    cout << "\n\n1,";
    cout << " 1,";

    for (int i = 1; i <= Num1; i++)
    {
        z = y + 2;
        cout << " " << z << ","; //It will print 3
        z = z * 2;
        cout << " " << z << ",";//It …
Run Code Online (Sandbox Code Playgroud)

c++ visual-c++ c++11

1
推荐指数
1
解决办法
98
查看次数

标签 统计

c++ ×1

c++11 ×1

visual-c++ ×1