+ 1
I wanna print factors of 2,3,5 only.
N=7; output should be 8. Everytime it prints the factor it should get incremented. 1,2,3,4,5,6,8,9,10,12,14,15,16,18,20••••••
7 odpowiedzi
+ 2
int n =12;
int i = 1;
int no=0;
for(i = 1 ; no < = n ; i++)
{
if(i%2==0 || i %3==0 || i %5==0)
no++;
}
printf("%d", i-1);
//This works i think.. Check it once..
But 1%2, 1%3, 1%5 not 0 so 1 not counted...
edit: Ajith use array to store factors and display values to easy understand what is missing... hope it helps..
+ 1
a, f = int(input()), 0
for x in range(a):
f += sum([(x+1)%y==0 for y in [2,3,5]]) == 1
print(f)
""" Prints only the individual factors; no overlap """
0
int n =12;
int i = 1;
int no;
for(i = 1 ; i < = n ; i++)
{
if(i%2==0 || i %3==0 || i %5==0)
no++;
else
continue;
}
printf("%d",no);
0
N=12;output would be 15
0
For n=12, how the output is 15? Give some clarity...
2,3,4,5,6,8,9,10,12 => 9 only..
0
1,2,3,4,5,6,8,9,10,12,14,15
n[12] = 15;
0
for n == 12, your actual code give you 9:
loop goes from 1 to n (included), so 'no' max value would be n... not 'factors' list: 1, 7,11, so 12-3 = 9...
the list you gave is not the result of your code ^^ (wich require some corrections to be ran)