Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Pastebin
- //nod in array
- #include <stdio.h>
- #include <math.h>
- #define SIZE 10
- int nod(int d,int element);
- int main()
- {
- int i,arr[SIZE],divider;//
- for(i=0;i<SIZE;i++)arr[i] = rand()%20+1;//populate array
- for(i=0;i<SIZE;i++)printf("%d\t",arr[i]);//print array
- divider= arr[0];
- for(i=1;i<SIZE;i++)divider = nod(divider,arr[i]);//
- return 0;
- }
- int nod(int div,int element)
- {
- int nod,i=2;
- nod =div*element;
- printf("\nnow for %d and %d\n",div,element);
- while(i<=nod/2)
- {
- if(!(element%i)&&!(div%i))
- {
- printf("dividable i is %d\n",i);
- element/=i;
- div/=i;
- nod/=i;
- printf(" i-%d,element-%d,div-%d,nod-%d\n",i,element,div,nod);
- }
- else //there might be duplication of digit(2,2...) 24=2*2*2*3
- i++;
- }
- return nod;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement