# counting common multiples of 2 numbers

This is a discussion on counting common multiples of 2 numbers within the C Programming forums, part of the General Programming Boards category; hey guys, i'm making a program that counts n common multiples of 2 numbers, like: the user enter value for ...

1. ## 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. 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