Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include <stdio.h>
  2. #define ARRSIZE 8
  3.  
  4. unsigned int periods[ARRSIZE] = {0};
  5. unsigned int test[] = {100,100,100};
  6. unsigned int diffy;
  7.  
  8. unsigned int diff(unsigned int a, unsigned int b);
  9. unsigned int checkgroup(unsigned int a[],unsigned int maxdiff);
  10. void enqueue(unsigned int queue[], unsigned int newvalue, unsigned int arraysize);
  11. void printqueue(unsigned int queue[], unsigned int arrysize);
  12.  
  13. int main()
  14. {
  15. unsigned int lastvalue = 0;
  16. while(1)
  17. {
  18. printf("Give 3 numbers in format and max differende X Y Z D:");
  19. scanf("%d %d %d %d",&test[0],&test[1],&test[2],&diffy);
  20. lastvalue = checkgroup(test,diffy);
  21. printf("\n%d\n",lastvalue);
  22. if(lastvalue != 0)
  23. {
  24. enqueue(periods,lastvalue,ARRSIZE);
  25. }
  26. printqueue(periods,ARRSIZE);
  27. }
  28. }
  29.  
  30. void printqueue(unsigned int queue[], unsigned int arraysize)
  31. {
  32. int i;
  33. for(i = 0; i < arraysize; i++)
  34. {
  35. printf("%d-",queue[i]);
  36. }
  37. printf("\n");
  38. }
  39.  
  40. void enqueue(unsigned int queue[], unsigned int newvalue, unsigned int arraysize)
  41. {
  42. int i;
  43. for(i = arraysize; i > 0; i--)
  44. {
  45. queue[i] = queue [i-1];
  46. //printf("moved %d to %d\n",i-1,i);
  47. }
  48. queue[0] = newvalue;
  49. }
  50.  
  51. unsigned int checkgroup(unsigned int a[],unsigned int maxdiff)
  52. {
  53. if(diff(a[0],a[1])<maxdiff)
  54. {
  55. if(diff(a[0],a[2])<maxdiff)
  56. {
  57. if(diff(a[1],a[2])<maxdiff)
  58. {
  59. return (a[0]+a[1]+a[2])/3;
  60. }
  61. }
  62. }
  63. return 0;
  64. }
  65.  
  66. unsigned int diff(unsigned int a, unsigned int b)
  67. {
  68. if(a > b)
  69. {
  70. return a-b;
  71. }
  72. else
  73. {
  74. return b-a;
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement