Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. void set(uint64_t* arr, int width, int height, uint64_t value, int x, int y)
  4. {
  5. if (arr == NULL)
  6. return;
  7. if (x < 0 || x >= width)
  8. return;
  9. if (y < 0 || y >= height)
  10. return;
  11. int index = y * width + x;
  12. arr[index] = value;
  13. }
  14. uint64_t get(const uint64_t* arr, int width, int height , int x, int y, uint64_t* result)
  15. {
  16. if (arr == NULL || result == NULL)
  17. return -1;
  18. if (x < 0 || x >= width)
  19. return -1;
  20. if (y < 0 || y >= height)
  21. return -1;
  22. int index = y * width + x;
  23. *result = arr[index];
  24. return 1;
  25. }
  26.  
  27. void show(const uint64_t* arr, int width, int height)
  28. {
  29. for (int r = 0; r < height; r++)
  30. {
  31. for (int c = 0; c < width; c++)
  32. {
  33. uint64_t value;
  34. get(arr, width, height, c, r, &value);
  35. printf("%d ", value);
  36. }
  37. printf("\n");
  38. }
  39. }
  40. uint64_t power(int num, int wyk)
  41. {
  42. uint64_t result = 1;
  43. for (int i = 0; i < wyk; i++)
  44. {
  45. result *= num;
  46. }
  47. return result;
  48. }
  49. int main()
  50. {
  51. uint64_t tab[5 * 10];
  52. int i, j;
  53. // void set(unsigned long int* arr, int width, int height, unsigned long int value, int x, int y)
  54. for (i = 0; i < 5; i++)
  55. {
  56. for (j = 0; j < 10; j++)
  57. {
  58. set(tab, 10, 5, ((i+1) * power(10, j+1)), j, i);
  59. }
  60. }
  61. show(tab, 10, 5);
  62.  
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement