Finch Finch Finch Finch - 1 month ago 5
C Question

How to print multipliers 3 and 5, but not print multipliers 15?

Here's the program I already made:

#include <stdio.h>

int main()
{

int i,n,t,t2;

printf("enter limit number: ");
scanf("%d", &n);

for (i = 1; i<=n; i++)
{
t = i * 3;
t2 = i * 5;

printf("%d, " ,t);
printf("%d, ",t2);
}
}


How to print multipliers of
3
and
5
, but not print multipliers
15
?

Answer

How to print multiplier 3 and 5, but not print multiplier 15?

So what can you know from this, the number that is being printed when divided with 15 must no produce remainder as 0 because then, it'd be multiplier of 15 so just put your printf statements in a if loop like this:

if((t % 15) != 0)
{
    printf("%d, " ,t);
}    
if((t2 % 15) != 0)
{    
    printf("%d, ",t2);
} 

see this for working example: https://ideone.com/2k0qLW

Comments