indentation on C not working for 1st ten lines of code -
the indentation in program, achieved \t
, being displayed after 10th day. don't know what's wrong it.
float penny= 0.01; int days = 1; while(31 >= days) { printf("day: %d \t amount: %f\n", days, penny); days += 1; penny *= 2; }
it's because of tab character (\t'
) advances cursor next modulo 8 column:
illustration:
01234567012375670123456701234567 <-- column number modulo 8 | | | | day: 9 amount: 2.560000 day: 10 amount: 5.120000 day: 11 amount: 10.240000
usually terminals behave this, i'm not sure if there standard defines this.
small program illustrating behaviour:
#include <stdio.h> int main() { int i,j,k; (i = 0; < 16; i++) { (j = 0; j < 4; j++) { (k = 0; k < i; k++) { printf ("*"); } printf ("\t"); } printf ("\n"); } }
output:
* * * * ** ** ** ** *** *** *** *** **** **** **** **** ***** ***** ***** ***** ****** ****** ****** ****** ******* ******* ******* ******* ******** ******** ******** ******** ********* ********* ********* ********* ********** ********** ********** ********** *********** *********** *********** *********** ************ ************ ************ ************ ************* ************* ************* ************* ************** ************** ************** ************** *************** *************** *************** ***************
Comments
Post a Comment