Tuesday, July 14, 2009

C programmers! help pls?

what is the code to:





1. display NEATLY a 10 x 10 multiplication table


2. display a 12-month calendar by asking user some info about the starting day





using nested "for" loops only..thanks a lot!

C programmers! help pls?
#include %26lt;stdio.h%26gt;








int main() {


// Part1.


for (int i = 1; i %26lt;= 10; i++) {


for (int j = 1; j %26lt;= 10; j++) {


printf("%3d ", i*j);


}


printf("\n");


}





// Part2.


int daysInMonth[] = {31,28,31,30,31,30,31,31,30,31,30,31};


char *monthName[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};


int w;


printf("what day is Jan 1 (0-Mon, 6-Sun):");


scanf("%d", %26amp;w);


for (int i = 0; i %26lt; 12; i++) {


printf("%12s\n", monthName[i]); // Month name in the middle.


for (int j = 0; j %26lt; (w%7); j++) printf(" "); // Empty spaces for the first week of the month.


for (int j = 0; j %26lt; daysInMonth[i]; j++) {


printf(" %2d", 1+j);


w = (w+1)%7;


if (w == 0) printf("\n"); // w is the weekday.


}


printf("\n");


}


return 0;


}
Reply:10 x 10:





for (x=1;x%26lt;=10;x++)


{


for(y=1;y%26lt;=10;y++)


{


cout%26lt;%26lt;x*y%26lt;%26lt;"\t";


}


cout%26lt;%26lt;"\n";


}


No comments:

Post a Comment