Calculate the exponential growth using while loop - C Statement

C examples for Statement:while

Description

Calculate the exponential growth using while loop

Demo Code

#include <stdio.h>

#define SQUARES 64             // squares on a checkerboard

int main(void){
    const double CROP = 2E16;  // world wheat production in wheat grains
    double current, total;
    int count = 1;
    //from w  ww  . j a va2  s .  c o m
    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;
        /* double grains on next square */
        total = total + current;     /* update total */
        printf("%4d %13.2e %12.2e %12.2e\n", count, current, total, total/CROP);
    }
    printf("That's all.\n");
    
    return 0;
}

Result


Related Tutorials