编程语言
首页 > 编程语言> > 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;
}

 

标签:count,语言,指数,程序,CROP,current,12.2,printf,total
来源: https://www.cnblogs.com/liujiaxin2018/p/15121417.html