C/C++教程

c语言中指数增长程序

本文主要是介绍c语言中指数增长程序,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

c语言中指数增长程序。

#include <stdio.h>
#define SQUARES 64

int main(void)
{
    const double CROP = 2E16;
    double current, total;
    int count = 1;
    
    printf("square    grains    total    ");
    printf("fraction of \n");
    printf("          added     grains   ");
    printf("world total\n");
    total = current = 1.0;
    
    printf("%4d %13.2e %12.2e %12.2e\n", count, current, total, total / CROP);
    
    while (count < SQUARES)
    {
        count = count + 1;
        current = 2.0 * current;
        total = total + current;
        printf("%4d %13.2e %12.2e %12.2e\n", count, current, total, total / CROP);
    }
    
    printf("that is all.\n");
    
    return 0;
}

 

这篇关于c语言中指数增长程序的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!