Skip to content

Instantly share code, notes, and snippets.

@Jackyjjc
Created September 4, 2014 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jackyjjc/1705d202974b446ec56f to your computer and use it in GitHub Desktop.
Save Jackyjjc/1705d202974b446ec56f to your computer and use it in GitHub Desktop.
my answer
#include<stdio.h>
int main(int argc, char** argv) {
int n, c;
int retVal;
if((retVal = scanf("%d %d", &n, &c)) != 2) {
printf("only scan in %d items\n", retVal);
return 1;
}
int numWholeRows = n / c;
int numWholeCols = n % c;
int numTotalRows = (n / c) + ((n % c == 0) ? 0 : 1);
printf("%d %d %d %d %d\n",n, c, numWholeRows, numWholeCols, numTotalRows);
int i,j;
for(i = 0; i < numTotalRows; i++) {
for(j = 0; j < c; j++) {
if(i >= numWholeRows && j >= numWholeCols) {
printf(" ");
continue;
}
printf("%d ", (i + 1) + j * ((j <= numWholeCols) ? numTotalRows : numWh
oleRows));
}
printf("\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment