Friday, July 31, 2009

C Programming Question (Printing Data in Columns)?

Below is my program. I have the two arrays print, but I want it to look good. I want it to print 3 rows like below, except aligned (Male being an array, female being the other array, and Age I would probally just do a variable set w/ age = 0 and each for statement on the output does age+1. Need to know how to do all this output? Thanks





Age Male Female


0 0 0


1 0 0


2 0 0





#include %26lt;stdio.h%26gt;


#include %26lt;math.h%26gt;


#define n 101





main(){





int male[n], female[n],i;


for (i=0; i%26lt;41; ++i)


male[i] = female[i] = 100;


for (i=41; i%26lt;101; ++i)


male[i] = female[i] = 0;





//PRINT MALE AND FEMALE ARRAYS (AGE 0 to 100)


printf("Female Array\n");


for(i=0; i%26lt;n; i++)


printf("%d\n", female[i]);


printf("Male Array\n");


for(i=0; i%26lt;n; i++)


printf("%d\n", male[i]);





return(0);


}

C Programming Question (Printing Data in Columns)?
Put a number between the % and d so something like %2d. You'll need to play with it a little to make them allign.

easter cards

No comments:

Post a Comment