Thread: subsequences in C

  1. #1
    Registered User
    Join Date
    Nov 2015
    Posts
    1

    Unhappy subsequences in C

    i have to find all the subsequences of all the prime numbers who has at least two digits(so i start from 11).we must define a max number ex.define maxnum 100.i am prohibited from use arrays and im a begginer. my code:

    Code:
    #include <stdio.h>#define MAXNUMB 100
    
    
    int main (void) 
    {
      int i,j,k,l,num,mult=1,mask,sub=0,tempnum,combs=0,max=1;
         for (i=11 ; i<MAXNUMB; i+=2) 
          { 
            for (j=3;j*j<=i;j+=2) 
             {  
               if (i%j==0) 
               
               
                 break; 
               
              }
             
               if (j*j>i) 
               {   
                tempnum=i; 
                while(tempnum!=0) 
                  {
                       tempnum/=10;
                     combs++; 
                     }
                   for ( k = 1; k <= combs; k++ ) 
                  {
                        max *= 2;
              }
                   for (k=1;k<combs-1;k++) 
                   {
                     mask=k;
                     mult=1;
                     sub=0;
                     num=i;
                     while (num!=0)
                        {
                         if (mask%2==1)
                           {
                             sub+=(num%10)*mult;
                             mult*=10;
                           }
                        num/=10;
                        mask/=2;
                        }
                     printf ("%d \n",sub);
                }
                 
           } 
         
        
      }
    }


    what i did wrong?can someone explain to me why the code doesnt gime the subsequences of 11-13-17 etc?
    Last edited by Kos Tas; 11-22-2015 at 10:56 PM.

  2. #2

Popular pages Recent additions subscribe to a feed

Tags for this Thread