fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. #define uint unsigned int
  6. #define WIDTH 40
  7. #define HEIGHT 40
  8. #define BLOCK_SIZE 5
  9.  
  10. void create_checker_row(uint* row, uint size_block, uint nb_col, uint offset )
  11. {
  12. uint ic;
  13. for (ic = size_block*offset ; ic < nb_col; ic+= 2*size_block )
  14. {
  15. memset( (row + ic) , 0, size_block*sizeof(uint) );
  16. }
  17. }
  18.  
  19. int main()
  20. {
  21. uint ir,ic;
  22.  
  23. // image creation
  24. uint* pixels = (uint*) malloc(WIDTH*HEIGHT*sizeof(uint));
  25. for (ir = 0; ir < WIDTH; ir++)
  26. {
  27. for ( ic = 0; ic < HEIGHT; ic++)
  28. {
  29. // arbitrary numbers
  30. pixels[ir*WIDTH + ic] = (ir*WIDTH + ic) % 57 ;
  31. printf("%d,", pixels[ir*WIDTH + ic] );
  32. }
  33. printf("\n");
  34. }
  35.  
  36. for (ir = 0; ir < WIDTH; ir++)
  37. {
  38. create_checker_row( pixels + ir*WIDTH , // pointer at the beggining of n-th row
  39. BLOCK_SIZE , // horizontal length for square
  40. WIDTH , // image width
  41. (ir/BLOCK_SIZE) % 2 // offset to create the checker pattern
  42. );
  43. }
  44.  
  45. // validation
  46. printf("\n");
  47. printf("Validation \n");
  48. printf("\n");
  49. for (ir = 0; ir < WIDTH; ir++)
  50. {
  51. for ( ic = 0; ic < HEIGHT; ic++)
  52. {
  53. printf("%d,", pixels[ir*WIDTH + ic] );
  54. }
  55. printf("\n");
  56. }
  57.  
  58. return 0;
  59. }
Success #stdin #stdout 0s 2384KB
stdin
Standard input is empty
stdout
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,
40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,
23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,0,1,2,3,4,5,
6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,
46,47,48,49,50,51,52,53,54,55,56,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,
29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,0,1,2,3,4,5,6,7,8,9,10,11,
12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,
52,53,54,55,56,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,
35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,
18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,0,
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,
24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,0,1,2,3,4,5,6,
7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,
47,48,49,50,51,52,53,54,55,56,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,
30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,0,1,2,3,4,5,6,7,8,9,10,11,12,
13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,
53,54,55,56,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,
36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,
19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,0,1,
2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,
42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,
25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,0,1,2,3,4,5,6,7,
8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
48,49,50,51,52,53,54,55,56,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,
31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,0,1,2,3,4,5,6,7,8,9,10,11,12,13,
14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,
54,55,56,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,
37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,
20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,0,1,2,
3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,
43,44,45,46,47,48,49,50,51,52,53,54,55,56,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,
26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,0,1,2,3,4,5,6,7,8,
9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,
49,50,51,52,53,54,55,56,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,
15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,
55,56,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,
38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,0,1,2,3,

Validation 

0,0,0,0,0,5,6,7,8,9,0,0,0,0,0,15,16,17,18,19,0,0,0,0,0,25,26,27,28,29,0,0,0,0,0,35,36,37,38,39,
0,0,0,0,0,45,46,47,48,49,0,0,0,0,0,55,56,0,1,2,0,0,0,0,0,8,9,10,11,12,0,0,0,0,0,18,19,20,21,22,
0,0,0,0,0,28,29,30,31,32,0,0,0,0,0,38,39,40,41,42,0,0,0,0,0,48,49,50,51,52,0,0,0,0,0,1,2,3,4,5,
0,0,0,0,0,11,12,13,14,15,0,0,0,0,0,21,22,23,24,25,0,0,0,0,0,31,32,33,34,35,0,0,0,0,0,41,42,43,44,45,
0,0,0,0,0,51,52,53,54,55,0,0,0,0,0,4,5,6,7,8,0,0,0,0,0,14,15,16,17,18,0,0,0,0,0,24,25,26,27,28,
29,30,31,32,33,0,0,0,0,0,39,40,41,42,43,0,0,0,0,0,49,50,51,52,53,0,0,0,0,0,2,3,4,5,6,0,0,0,0,0,
12,13,14,15,16,0,0,0,0,0,22,23,24,25,26,0,0,0,0,0,32,33,34,35,36,0,0,0,0,0,42,43,44,45,46,0,0,0,0,0,
52,53,54,55,56,0,0,0,0,0,5,6,7,8,9,0,0,0,0,0,15,16,17,18,19,0,0,0,0,0,25,26,27,28,29,0,0,0,0,0,
35,36,37,38,39,0,0,0,0,0,45,46,47,48,49,0,0,0,0,0,55,56,0,1,2,0,0,0,0,0,8,9,10,11,12,0,0,0,0,0,
18,19,20,21,22,0,0,0,0,0,28,29,30,31,32,0,0,0,0,0,38,39,40,41,42,0,0,0,0,0,48,49,50,51,52,0,0,0,0,0,
0,0,0,0,0,6,7,8,9,10,0,0,0,0,0,16,17,18,19,20,0,0,0,0,0,26,27,28,29,30,0,0,0,0,0,36,37,38,39,40,
0,0,0,0,0,46,47,48,49,50,0,0,0,0,0,56,0,1,2,3,0,0,0,0,0,9,10,11,12,13,0,0,0,0,0,19,20,21,22,23,
0,0,0,0,0,29,30,31,32,33,0,0,0,0,0,39,40,41,42,43,0,0,0,0,0,49,50,51,52,53,0,0,0,0,0,2,3,4,5,6,
0,0,0,0,0,12,13,14,15,16,0,0,0,0,0,22,23,24,25,26,0,0,0,0,0,32,33,34,35,36,0,0,0,0,0,42,43,44,45,46,
0,0,0,0,0,52,53,54,55,56,0,0,0,0,0,5,6,7,8,9,0,0,0,0,0,15,16,17,18,19,0,0,0,0,0,25,26,27,28,29,
30,31,32,33,34,0,0,0,0,0,40,41,42,43,44,0,0,0,0,0,50,51,52,53,54,0,0,0,0,0,3,4,5,6,7,0,0,0,0,0,
13,14,15,16,17,0,0,0,0,0,23,24,25,26,27,0,0,0,0,0,33,34,35,36,37,0,0,0,0,0,43,44,45,46,47,0,0,0,0,0,
53,54,55,56,0,0,0,0,0,0,6,7,8,9,10,0,0,0,0,0,16,17,18,19,20,0,0,0,0,0,26,27,28,29,30,0,0,0,0,0,
36,37,38,39,40,0,0,0,0,0,46,47,48,49,50,0,0,0,0,0,56,0,1,2,3,0,0,0,0,0,9,10,11,12,13,0,0,0,0,0,
19,20,21,22,23,0,0,0,0,0,29,30,31,32,33,0,0,0,0,0,39,40,41,42,43,0,0,0,0,0,49,50,51,52,53,0,0,0,0,0,
0,0,0,0,0,7,8,9,10,11,0,0,0,0,0,17,18,19,20,21,0,0,0,0,0,27,28,29,30,31,0,0,0,0,0,37,38,39,40,41,
0,0,0,0,0,47,48,49,50,51,0,0,0,0,0,0,1,2,3,4,0,0,0,0,0,10,11,12,13,14,0,0,0,0,0,20,21,22,23,24,
0,0,0,0,0,30,31,32,33,34,0,0,0,0,0,40,41,42,43,44,0,0,0,0,0,50,51,52,53,54,0,0,0,0,0,3,4,5,6,7,
0,0,0,0,0,13,14,15,16,17,0,0,0,0,0,23,24,25,26,27,0,0,0,0,0,33,34,35,36,37,0,0,0,0,0,43,44,45,46,47,
0,0,0,0,0,53,54,55,56,0,0,0,0,0,0,6,7,8,9,10,0,0,0,0,0,16,17,18,19,20,0,0,0,0,0,26,27,28,29,30,
31,32,33,34,35,0,0,0,0,0,41,42,43,44,45,0,0,0,0,0,51,52,53,54,55,0,0,0,0,0,4,5,6,7,8,0,0,0,0,0,
14,15,16,17,18,0,0,0,0,0,24,25,26,27,28,0,0,0,0,0,34,35,36,37,38,0,0,0,0,0,44,45,46,47,48,0,0,0,0,0,
54,55,56,0,1,0,0,0,0,0,7,8,9,10,11,0,0,0,0,0,17,18,19,20,21,0,0,0,0,0,27,28,29,30,31,0,0,0,0,0,
37,38,39,40,41,0,0,0,0,0,47,48,49,50,51,0,0,0,0,0,0,1,2,3,4,0,0,0,0,0,10,11,12,13,14,0,0,0,0,0,
20,21,22,23,24,0,0,0,0,0,30,31,32,33,34,0,0,0,0,0,40,41,42,43,44,0,0,0,0,0,50,51,52,53,54,0,0,0,0,0,
0,0,0,0,0,8,9,10,11,12,0,0,0,0,0,18,19,20,21,22,0,0,0,0,0,28,29,30,31,32,0,0,0,0,0,38,39,40,41,42,
0,0,0,0,0,48,49,50,51,52,0,0,0,0,0,1,2,3,4,5,0,0,0,0,0,11,12,13,14,15,0,0,0,0,0,21,22,23,24,25,
0,0,0,0,0,31,32,33,34,35,0,0,0,0,0,41,42,43,44,45,0,0,0,0,0,51,52,53,54,55,0,0,0,0,0,4,5,6,7,8,
0,0,0,0,0,14,15,16,17,18,0,0,0,0,0,24,25,26,27,28,0,0,0,0,0,34,35,36,37,38,0,0,0,0,0,44,45,46,47,48,
0,0,0,0,0,54,55,56,0,1,0,0,0,0,0,7,8,9,10,11,0,0,0,0,0,17,18,19,20,21,0,0,0,0,0,27,28,29,30,31,
32,33,34,35,36,0,0,0,0,0,42,43,44,45,46,0,0,0,0,0,52,53,54,55,56,0,0,0,0,0,5,6,7,8,9,0,0,0,0,0,
15,16,17,18,19,0,0,0,0,0,25,26,27,28,29,0,0,0,0,0,35,36,37,38,39,0,0,0,0,0,45,46,47,48,49,0,0,0,0,0,
55,56,0,1,2,0,0,0,0,0,8,9,10,11,12,0,0,0,0,0,18,19,20,21,22,0,0,0,0,0,28,29,30,31,32,0,0,0,0,0,
38,39,40,41,42,0,0,0,0,0,48,49,50,51,52,0,0,0,0,0,1,2,3,4,5,0,0,0,0,0,11,12,13,14,15,0,0,0,0,0,
21,22,23,24,25,0,0,0,0,0,31,32,33,34,35,0,0,0,0,0,41,42,43,44,45,0,0,0,0,0,51,52,53,54,55,0,0,0,0,0,