C ++ print large numbers, how do not want to use scientific notation?

Add such a sentence before you print:

cout.setf(ios::fixed,ios::floatfield);

 

Below is an example:

A young man with the future father of the bride price to discuss the matter.

Future father said: "This way, you give me a penny the first day, the next day my two cents, double the previous day more than a day, for a month, will be able to marry my daughter to go home!"

The young man thought: that kind of money, the prospective father to me pretty good thing! Apart from anything else I agreed.

We write programs in C ++ to help him count the dowry total of how much money :( cynicism series)

 

#include<iostream>

using namespace std;

int main()
{
    cout.setf(ios::fixed,ios::floatfield);
    double i = 0.01;
    double sum = 0;
    for(int x = 1; x < 31; x ++)
    {
        i *= 2;
        sum += i;
    }
    cout << "彩礼总共需要:" << sum << "元" << endl;
    return 0;   
}

Month 30-day count, the result is Jiang Zi:

One, ten, a hundred, a thousand, ten thousand, thousands, millions, millions! I go to Le, 21 million bride price you dare to believe!

Guess you like

Origin www.cnblogs.com/qscfyuk/p/12323497.html