Prime digits

This is a discussion on Prime digits within the C Programming forums, part of the General Programming Boards category; I am doing multiplication of numbers such that every digits is a prime, i don,t know what it the problem ...

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    59

    Prime digits

    I am doing multiplication of numbers such that every digits is a prime,
    i don,t know what it the problem ....when i run my program ,i don,t get all prime...i don,t know where the problem is from.please help me tell me what i did wrong.

    Code:
    
    #include <math.h>
    #include <stdbool.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    bool check_prime(int);
    
    int main(){
    	
    int flag=0;
    int multiplicand, multiplier,result;
        int partial_product1,partial_product2;
        
        for ( multiplicand = 100; multiplicand <= 999; multiplicand++ ) {
         
    
            for ( multiplier = 10; multiplier <= 99; multiplier++ ) {
            	
            
               
                
              int result = multiplicand * multiplier;
               	int digit51=result%10;
    		  	int digit52=result/10%10;
    		  	int digit53=result/100%10;
               	int digit54=result/1000%10;
    		  	int digit55=result/10000%10;
     			if((check_prime(digit51))==0)
     			continue;
     			if((check_prime(digit52))==0)
     			continue;
       			if((check_prime(digit53))==0)
     			continue;
     			if((check_prime(digit54))==0)
     			continue;
     			if((check_prime(digit55))==0)
     			continue;
         		int digit11=result%10;
    		  	int digit12=result/10%10;
    		  	int digit13=result/100%10;
               
    		  	if((check_prime(digit11))==0)
     			continue;
     			if((check_prime(digit12))==0)
     			continue;
       			if((check_prime(digit13))==0)
     			continue;
                    
               	int digit21=result%10;
    		  	int digit22=result/10%10;   
    		  	
    	  		if((check_prime(digit21))==0)
     			continue;
     			if((check_prime(digit22))==0)
     			continue;
     			
    			partial_product1 = multiplicand * digit21;
     			int digit31= partial_product1%10;
     			int digit32= partial_product1/10%10;
     			int digit33= partial_product1/100%10;
     			int digit34= partial_product1/1000%10;
     			
     		
     			
     			if((check_prime(digit31))==0)
     			continue;
     			if((check_prime(digit32))==0)
     			continue;
       			if((check_prime(digit33))==0)
     			continue;
               	if((check_prime(digit34))==0)
     			continue;
     			
     			partial_product2 = multiplicand * digit22;
     			
     			int digit41= partial_product2%10;
     			int digit42= partial_product2/10%10;
     			int digit43= partial_product2/100%10;
     			int digit44= partial_product2/1000%10;
     			
     			if((check_prime(digit41))==0)
     			continue;
     			if((check_prime(digit42))==0)
     			continue;
       			if((check_prime(digit43))==0)
     			continue;
               	if((check_prime(digit44))==0)
     			continue;
     			
    		  	
     				printf("             \n");
     				printf("             \n");
                    printf("%5d\n",multiplicand);
                    printf("\n");
                    printf("%5d\n",multiplier);
                    printf("-----\n");
                    printf("%5d\n",partial_product1);
                    printf("\n");
                    printf("%4d\n",partial_product2);
                    printf("-----\n");
                    printf("%d\n",result);
                    printf("             \n");
                    printf("             \n");
                   
            }
            
        }
    }
    
    
    bool check_prime(int n)
    { 
     if((n%2)==0){
      return false;
     }
     int c=0;
     for(int i=1;i<=n;i++)
     {	
     
     if((n%i)==0)
     {
     	c=c+1;
     }
     
    }
    if(c==2)
    {
    	return true;
    }
    }

  2. #2
    Registered User
    Join Date
    Jul 2011
    Location
    Bangalore,India
    Posts
    24
    Quote Originally Posted by code_lover View Post
    I am doing multiplication of numbers such that every digits is a prime,
    i don,t know what it the problem ....when i run my program ,i don,t get all prime...i don,t know where the problem is from.please help me tell me what i did wrong.

    Code:
    
    #include <math.h>
    #include <stdbool.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    bool check_prime(int);
    
    int main(){
    	
    int flag=0;
    int multiplicand, multiplier,result;
        int partial_product1,partial_product2;
        
        for ( multiplicand = 100; multiplicand <= 999; multiplicand++ ) {
         
    
            for ( multiplier = 10; multiplier <= 99; multiplier++ ) {
            	
            
               
                
              int result = multiplicand * multiplier;
               	
                            int digit51=result%10;
    		  	int digit52=result/10%10;
    		  	int digit53=result/100%10;
               	        int digit54=result/1000%10;
    		  	int digit55=result/10000%10;
     			
                            if((check_prime(digit51))==0)
     			continue;
     			if((check_prime(digit52))==0)
     			continue;
       			if((check_prime(digit53))==0)
     			continue;
     			if((check_prime(digit54))==0)
     			continue;
     			if((check_prime(digit55))==0)
     			continue;
         		        
                            
                            int digit11=result%10;
    		  	int digit12=result/10%10;
    		  	int digit13=result/100%10;
    //shouldnt it be multiplicand
               
    		  	if((check_prime(digit11))==0)
     			continue;
     			if((check_prime(digit12))==0)
     			continue;
       			if((check_prime(digit13))==0)
     			continue;
                    
               	        int digit21=result%10;
    		  	int digit22=result/10%10; //shouldnt this be multiplier  
    		  	
    	  		if((check_prime(digit21))==0)
     			continue;
     			if((check_prime(digit22))==0)
     			continue;
    //shouldnt this block be first...check the digits of multiplicand and multiplier for prime....
    
     			
    			partial_product1 = multiplicand * digit21;
     			int digit31= partial_product1%10;
     			int digit32= partial_product1/10%10;
     			int digit33= partial_product1/100%10;
     			int digit34= partial_product1/1000%10;
     			
     		
     			
     			if((check_prime(digit31))==0)
     			continue;
     			if((check_prime(digit32))==0)
     			continue;
       			if((check_prime(digit33))==0)
     			continue;
               	if((check_prime(digit34))==0)
     			continue;
     			
     			partial_product2 = multiplicand * digit22;
     			
     			int digit41= partial_product2%10;
     			int digit42= partial_product2/10%10;
     			int digit43= partial_product2/100%10;
     			int digit44= partial_product2/1000%10;
     			
     			if((check_prime(digit41))==0)
     			continue;
     			if((check_prime(digit42))==0)
     			continue;
       			if((check_prime(digit43))==0)
     			continue;
               	if((check_prime(digit44))==0)
     			continue;
     			
    		  	
     				printf("             \n");
     				printf("             \n");
                    printf("%5d\n",multiplicand);
                    printf("\n");
                    printf("%5d\n",multiplier);
                    printf("-----\n");
                    printf("%5d\n",partial_product1);
                    printf("\n");
                    printf("%4d\n",partial_product2);
                    printf("-----\n");
                    printf("%d\n",result);
                    printf("             \n");
                    printf("             \n");
                   
            }
            
        }
        return 0;//ur type is int main()
    }
    
    
    bool check_prime(int n)
    { 
     if((n%2)==0 && n!=2){//2 is prime
      return false;
     }
     int c=0;
     for(int i=1;i<=n;i++)
     {	
     
     if((n%i)==0)
     {
     	c=c+1;
     }
     
    }
    if(c==2)
    {
    	return true;
    }
    //there must be a return false..for c>2.
    }
    check the things i have pointed out...can u give an example of such numbers....like tell the sample multplicand and multiplier which satisfies your condition...including the digits in partial and final product to b prime...is that even possible to find such a number....after i tweaked your program...i don't get any values...Are you sure there exists a valid sample....
    Last edited by subhash.rao; 08-12-2011 at 04:44 AM. Reason: doubting the question after trying to think of a valid sample....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 02-19-2009, 09:32 PM
  2. Help with digits
    By jrice528 in forum C++ Programming
    Replies: 4
    Last Post: 10-03-2007, 06:04 PM
  3. Replies: 3
    Last Post: 03-29-2005, 03:24 PM
  4. Max Digits
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 02-09-2002, 05:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21