amrendra2018

c program to find Quark pair

Aug 13th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.59 KB | None | 0 0
  1. #include<stdio.h>
  2. int bin(int );
  3.  
  4. int bin(int n) //this fn retuns total no. of 1 in n * n
  5. {
  6.    int i=0,j,n1,t,arr[100],count=0;
  7.    t=n;
  8.    while(n!=0)
  9.      {
  10.         n1=n%2;
  11.         n=n/2;
  12.         arr[i++]=n1;
  13.    
  14.      } 
  15.  
  16.     for(j=i-1;j>=0;j--)
  17.       {
  18.        
  19.         if(arr[j]==1)
  20.         count=count+1;
  21.       }
  22.      
  23.       return count*t;
  24. }
  25.  
  26. int main()
  27. {
  28.     int n,i,j,y,z;
  29.     printf("Enter value of n:");
  30.     scanf("%d",&n);
  31.    
  32.     for(i=0;i<=n;i++)
  33.     {
  34.         y=bin(i);
  35.        
  36.         for(j=i+1;j<=n;j++)
  37.         {
  38.             z=bin(j);
  39.            
  40.             if(y==z)
  41.             {
  42.               printf("Quarks pair: %d %d\n" ,i,j);
  43.             }
  44.            
  45.         }
  46.        
  47.     }
  48.    
  49. }
Add Comment
Please, Sign In to add comment