Click here to Skip to main content
15,912,329 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questiontrie Pin
tmnnik11-Feb-09 10:57
tmnnik11-Feb-09 10:57 
AnswerRe: trie Pin
Stuart Dootson11-Feb-09 11:12
professionalStuart Dootson11-Feb-09 11:12 
QuestionRe: trie Pin
led mike11-Feb-09 11:26
led mike11-Feb-09 11:26 
AnswerRe: trie Pin
Stuart Dootson11-Feb-09 12:15
professionalStuart Dootson11-Feb-09 12:15 
Questionc program that inputs 5 pairs of integers and determine if the second one is multiple of the first one Pin
raeiko11-Feb-09 10:42
raeiko11-Feb-09 10:42 
AnswerRe: c program that inputs 5 pairs of integers and determine if the second one is multiple of the first one Pin
Stuart Dootson11-Feb-09 11:07
professionalStuart Dootson11-Feb-09 11:07 
GeneralRe: c program that inputs 5 pairs of integers and determine if the second one is multiple of the first one Pin
raeiko11-Feb-09 11:31
raeiko11-Feb-09 11:31 
GeneralRe: c program that inputs 5 pairs of integers and determine if the second one is multiple of the first one Pin
Stuart Dootson11-Feb-09 12:30
professionalStuart Dootson11-Feb-09 12:30 
I see what you've done. You've got the loop in main and multiple, but you're passing single integers into multiple. There are two solutions (both built & tested under darwin-gcc-4.0.1):

  1. Call multiple in the loop and remove the loop in multiple:
    /* Program that reads a pair of numbers and determines whether the second number is multiple of the first one */
    
    #include <stdio.h>
    
    int multiple ( int j, int z); /* function prototype */
    
    int main( void ) /* function main begins program execution */
    {
       int num1, num2, x, i; /* declare variables */
    
       for ( x = 1; x <= 5; x++ )
       {	
          printf( "Enter the first number:" ); /* prompt for input */
          scanf("%d", &num1 ); /* read number from user */
    
          if ( num1 != 0)
          {
             printf( "Enter the second number:" ); /* prompt for input */
             scanf("%d", &num2 ); /* read number from user */
          } 
          else
          {
             break;
             printf( "\nBroke from loop because num1 must be greater than 0\n" ); /* break loop if num1 = = 0 */
          }
          multiple( num1, num2);
       }
    
       return 0;
    }
    
    int multiple ( int j, int z ) /* copy of the argment to function */
    {	
       int result;
    
       result = z % j;
    
       if( result == 0)
       {
          printf( "%d is multiple of %d\n", z, j );
       }
       else
       {
          printf( "%d is not multiple of %d\n", z, j );
       }
          return result;
    } /* end of multiple function */
  2. Gather the numbers into two arrays and process them in one call to multiple:
    /* Program that reads a pair of numbers and determines whether the second number is multiple of the first one */
    
    #include <stdio.h>
    
    int multiple ( int* j, int* z, int n); /* function prototype */
    
    int main( void ) /* function main begins program execution */
    {
       int num1[5] = {0};
       int num2[5] = {0};
       int x, i; /* declare variables */
    
       for ( x = 1; x <= 5; x++ )
       {	
          printf( "Enter the first number:" ); /* prompt for input */
          scanf("%d", &(num1[x-1]) ); /* read number from user */
    
          if ( num1[x-1] != 0)
          {
             printf( "Enter the second number:" ); /* prompt for input */
             scanf("%d", &(num2[x-1]) ); /* read number from user */
          } 
          else
          {
             break;
             printf( "\nBroke from loop because num1 must be greater than 0\n" ); /* break loop if num1 = = 0 */
          }
       }
    
       multiple( num1, num2, x-1);
    
       return 0;
    }
    
    int multiple ( int* j, int* z, int numValues) /* copy of the argment to function */
    {	
       int y; /* counter */
    
       int result;
    
    
       for (y=0;y<numValues;++y)
       {
          result = z[y] % j[y];
          if( result == 0)
          {
             printf( "%d is multiple of %d\n", z[y], j[y] );
          }
          else
          {
             printf( "%d is not multiple of %d\n", z[y], j[y] );
          }
       }
       return result;
    } /* end of multiple function */
  3. Personally, I prefer the first one - why mess with arrays when you don't have to?

    Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

GeneralRe: c program that inputs 5 pairs of integers and determine if the second one is multiple of the first one Pin
raeiko11-Feb-09 13:28
raeiko11-Feb-09 13:28 
AnswerRe: c program that inputs 5 pairs of integers and determine if the second one is multiple of the first one Pin
CPallini11-Feb-09 11:59
mveCPallini11-Feb-09 11:59 
QuestionRe: c program that inputs 5 pairs of integers and determine if the second one is multiple of the first one Pin
David Crow12-Feb-09 3:24
David Crow12-Feb-09 3:24 
QuestionTrying to load a wave file into a class from the resource's Pin
simon alec smith11-Feb-09 10:05
simon alec smith11-Feb-09 10:05 
AnswerRe: Trying to load a wave file into a class from the resource's Pin
Stuart Dootson11-Feb-09 11:05
professionalStuart Dootson11-Feb-09 11:05 
QuestionA quick question about Microsoft Visual C++ Runtimes and Visual Studio 2008. Pin
santiageitorx11-Feb-09 7:21
santiageitorx11-Feb-09 7:21 
AnswerRe: A quick question about Microsoft Visual C++ Runtimes and Visual Studio 2008. Pin
led mike11-Feb-09 7:44
led mike11-Feb-09 7:44 
AnswerRe: A quick question about Microsoft Visual C++ Runtimes and Visual Studio 2008. Pin
Stuart Dootson11-Feb-09 7:52
professionalStuart Dootson11-Feb-09 7:52 
GeneralRe: A quick question about Microsoft Visual C++ Runtimes and Visual Studio 2008. Pin
led mike11-Feb-09 8:25
led mike11-Feb-09 8:25 
JokeRe: A quick question about Microsoft Visual C++ Runtimes and Visual Studio 2008. Pin
Perspx11-Feb-09 8:39
Perspx11-Feb-09 8:39 
GeneralRe: A quick question about Microsoft Visual C++ Runtimes and Visual Studio 2008. Pin
Stuart Dootson11-Feb-09 8:56
professionalStuart Dootson11-Feb-09 8:56 
GeneralRe: A quick question about Microsoft Visual C++ Runtimes and Visual Studio 2008. Pin
santiageitorx11-Feb-09 8:04
santiageitorx11-Feb-09 8:04 
GeneralRe: A quick question about Microsoft Visual C++ Runtimes and Visual Studio 2008. Pin
Stuart Dootson11-Feb-09 9:07
professionalStuart Dootson11-Feb-09 9:07 
QuestionHow to manage image position after changing screen resolution? Pin
Supra211-Feb-09 7:03
Supra211-Feb-09 7:03 
AnswerRe: How to manage image position after changing screen resolution? Pin
Cedric Moonen11-Feb-09 7:36
Cedric Moonen11-Feb-09 7:36 
QuestionHow not to lose focus when a child dialog is created Pin
materatsu11-Feb-09 5:36
materatsu11-Feb-09 5:36 
QuestionRe: How not to lose focus when a child dialog is created Pin
David Crow11-Feb-09 5:37
David Crow11-Feb-09 5:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.