Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define ARRSIZE 8
- unsigned int periods[ARRSIZE] = {0};
- unsigned int test[] = {100,100,100};
- unsigned int diffy;
- unsigned int diff(unsigned int a, unsigned int b);
- unsigned int checkgroup(unsigned int a[],unsigned int maxdiff);
- void enqueue(unsigned int queue[], unsigned int newvalue, unsigned int arraysize);
- void printqueue(unsigned int queue[], unsigned int arrysize);
- int main()
- {
- unsigned int lastvalue = 0;
- while(1)
- {
- printf("Give 3 numbers in format and max differende X Y Z D:");
- scanf("%d %d %d %d",&test[0],&test[1],&test[2],&diffy);
- lastvalue = checkgroup(test,diffy);
- printf("\n%d\n",lastvalue);
- if(lastvalue != 0)
- {
- enqueue(periods,lastvalue,ARRSIZE);
- }
- printqueue(periods,ARRSIZE);
- }
- }
- void printqueue(unsigned int queue[], unsigned int arraysize)
- {
- int i;
- for(i = 0; i < arraysize; i++)
- {
- printf("%d-",queue[i]);
- }
- printf("\n");
- }
- void enqueue(unsigned int queue[], unsigned int newvalue, unsigned int arraysize)
- {
- int i;
- for(i = arraysize; i > 0; i--)
- {
- queue[i] = queue [i-1];
- //printf("moved %d to %d\n",i-1,i);
- }
- queue[0] = newvalue;
- }
- unsigned int checkgroup(unsigned int a[],unsigned int maxdiff)
- {
- if(diff(a[0],a[1])<maxdiff)
- {
- if(diff(a[0],a[2])<maxdiff)
- {
- if(diff(a[1],a[2])<maxdiff)
- {
- return (a[0]+a[1]+a[2])/3;
- }
- }
- }
- return 0;
- }
- unsigned int diff(unsigned int a, unsigned int b)
- {
- if(a > b)
- {
- return a-b;
- }
- else
- {
- return b-a;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement