Thread: counting common multiples of 2 numbers

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    6

    counting common multiples of 2 numbers

    hey guys,
    i'm making a program that counts n common multiples of 2 numbers, like:
    the user enter value for n (32 for exmple), and from 1 to 32 i have to count the number of multiples of 3 that aren't multiples of 7.
    The code i've done, doesnt work, dont know why, please help me:

    Code:
    #include <stdio.h>
    main(){
    int counter,n,multiple3, multiple7, multiple;
    
    printf("Enter n: ");
    scanf("%d", &n);
    
    for(counter=1;counter<=n;counter++){
    multiple3=3*counter;
    scanf("%d",&multiple3);
    }
    
    for(counter=1;counter<=n;counter++){
    multiple7=7*counter;
    scanf("%d",&multiple7);
    }
    
    while (multiple3!=multiplo7)
    multiple=multiple3;
    
    printf("%d", multiple);
    
    }

  2. #2
    UCF Mystic_Skies's Avatar
    Join Date
    Oct 2004
    Posts
    33
    I know this does not solve your problem completely but here's some minor corrections such as a misspelling that was causing compilation errors. At least it compiles now. Other than that, I really was not sure on the algorithm you were wanting to solve?

    Code:
    #include <stdio.h>
    
    /* main needs to return int */
    int main( void )
    {
       int counter, n, multiple3, multiple7, multiple;
    
       printf( "Enter n: " );
       scanf( "%i", &n );
       
       /* two for loops are redundant considering the same parameters */
       for( counter = 1; counter <= n; counter++ )
       {
          /* not exactly sure why the scanf( )s were there */
          multiple7 = 7 * counter;      
          multiple3 = 3 * counter;  
          
          /* multiple7 was misspelled */
          /* maybe you wanted an "if" statement inside of your for loop? */
          if ( multiple3 != multiple7 )
          {
             multiple = multiple3;
             printf( "%d", multiple );
          }      
       }
       
       return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  2. Lowest Common Factor
    By PJYelton in forum C++ Programming
    Replies: 9
    Last Post: 12-23-2002, 09:30 AM
  3. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-03-2002, 11:15 AM
  4. Counting Page Numbers
    By dayknight in forum C++ Programming
    Replies: 2
    Last Post: 11-11-2002, 06:52 AM
  5. Counting Occurrance of Numbers
    By dat in forum C Programming
    Replies: 6
    Last Post: 11-03-2002, 02:11 PM