Thread: Please, can someone give a hand on this

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

    Please, can someone give a hand on this

    I have ran the code several times, but its is not outputting anything!!!!!!!!
    It suppose to display the multiplication of two numbers whose all the sum of the digits in the column is equal i.e The four columns have an equal sum.


    Code:
    
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(void) {
    
        int multiplicand, multiplier;
        for ( multiplicand = 100; multiplicand <= 999; multiplicand++ ) 
    
            for ( multiplier = 10; multiplier <= 99; multiplier++ ) {
    
                int partial_product1, partial_product2, result;
                
                
    
                result = multiplicand * multiplier;
    
                partial_product1 = multiplier  % 10;
    
                partial_product2 = multiplier / 10;
    
                if ( partial_product1 < 1000 )
    
                    continue;
                if ( partial_product2 >= 1000 )
    
                    continue;
    
                if ( result > 9999 )
    
                    continue;
    
                int s1 ,s2 ,s3 , s4 ,s5 , s_sum;
                
    
                s1 = multiplicand % 10;
    
    			s2 = multiplier % 10;
    
                s3 = partial_product1 % 10;
                
                s4 = partial_product2 % 10;
    
                s5 = result % 10;
                
                s_sum = s1 + s2 + s3 + s4 + s5;
                
    
                int b1 ,b2 ,b3 ,b4 , b5,b_sum;
    
                b1 = multiplicand /10 % 10;
    
                b2 = multiplier /10 % 10;
    
                b3 = partial_product1 /10 % 10;
    
                b4 = partial_product2 /10 % 10;
                
                b5 = result / 10 %100;
    			 
    			b_sum = b1 + b2 + b3 + b4 + b5;
    			
    			int c1, c2 ,c3,c4,c5,c_sum;
    			
    			c1 = multiplicand /100 % 10;
    			
    			c2 = multiplier /100 % 10;
    
                c3 = partial_product1 /100 % 10;
    
                c4 = partial_product2 / 100 % 10;
                
                c5 = result / 100% 10;
                
                c_sum = c1 + c2 + c3 + c4 + c5;
    
                int f1 , f2 , f3 , f4 , f5 ,f_sum;
                
               	f1 = multiplicand / 1000 % 10;
    			
    			f2 = multiplier / 1000 % 10;
    
                f3 = partial_product1 / 1000 % 10;
    
                f4 = partial_product2 / 1000 % 10;
                
                f5 = result  / 1000 % 10;
                
                f_sum = f1 + f2 + f3 + f4 + f5;
                
                if ( s_sum != b_sum && f_sum != s_sum && c_sum != s_sum  )
    			 
    			continue;
    			
    			printf ( "%d" ,multiplicand );
    			
    			printf ( "%d" ,multiplier);
    			
    		 	printf ( "%d" ,partial_product1);
    		 	
    			printf ( "%d" ,partial_product2);
    			
    			printf ( "%d" ,result);
                
              
            }
      
        
        return EXIT_SUCCESS;
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
                partial_product1 = multiplier  % 10;
    
                partial_product2 = multiplier / 10;
    
                if ( partial_product1 < 1000 )
    
                    continue;
    Why would you ever expect it to get past that if check?


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    I count 4 different places where the OP has defined variables, isn't C99 great!?!

    @OP- You really should think about how you are structuring your program flow, you are verging on excessive with your use of continue.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  4. #4
    Registered User
    Join Date
    Aug 2011
    Posts
    59
    i have changed that to

    if ( partial_product1 > 9999 )

    but it is output a different thing.
    any idea !!???


    * * *
    x * *
    ----------
    * * * *
    * * *
    ----------
    * * * *

  5. #5
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by code_lover View Post
    but it is output a different thing.
    any idea !!???


    * * *
    x * *
    ----------
    * * * *
    * * *
    ----------
    * * * *
    No, I have no idea what you are saying. Please explain yourself more clearly and use examples of what is going wrong and what you expect to have happen.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  6. #6
    Registered User
    Join Date
    Apr 2011
    Location
    dust
    Posts
    70
    Quote Originally Posted by code_lover View Post
    i have changed that to

    if ( partial_product1 > 9999 )

    but it is output a different thing.
    any idea !!???


    * * *
    x * *
    ----------
    * * * *
    * * *
    ----------
    * * * *

    What exactly you want to implement?
    Give some comments on your previous code, then only we can understand what u did and what u supposed to???????

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need a hand
    By eurikau in forum C Programming
    Replies: 0
    Last Post: 07-17-2007, 08:50 AM
  2. infix to postfix .... give me a hand please !!
    By backtolife in forum C++ Programming
    Replies: 6
    Last Post: 10-30-2006, 01:48 PM
  3. Replies: 1
    Last Post: 06-29-2004, 05:23 PM
  4. what are some other 'life skills' that can go hand in hand with programming
    By Shadow12345 in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 01-17-2003, 02:34 PM
  5. Hand Up
    By Rolf in forum C++ Programming
    Replies: 1
    Last Post: 12-02-2001, 08:44 AM