Advertisement
NabilaShova

Number of Relative Primes in Array

May 17th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.49 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int i,j,n, c=0;
  5.     scanf("%d", &n);
  6.     int a[n];
  7.     for(i=0; i<n; i++)
  8.     {
  9.         scanf("%d", &a[i]);
  10.     }
  11.     for(i=0; i<n; i++)
  12.     {
  13.         for(j=i+1; j<n; j++)
  14.         {
  15.             if((a[i] % a[j] != 0) && (a[j] % a[i] != 0))
  16.             {
  17.                 printf("%d and %d are relative primes\n", a[i], a[j]);
  18.                 c++;
  19.             }
  20.         }
  21.     }
  22.     printf("Number of relative primes is: %d", c);
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement