Use float number to control for loop - C++ Statement

C++ examples for Statement:for

Description

Use float number to control for loop

Demo Code

#include <iostream>

using namespace std;

int main()//from  w  w  w .j  a va 2 s  .  c  o  m
{
    double x = 0.0;
    double i;

    for (i = 0.0; i <= 100; i+=0.1)
    {
        x += i;
    }

    cout << x << endl;

    return 0;
}

Result


Related Tutorials