-
check for y condition
let say i have two loops and i want to check if the varibles from one loop can evenly divided like this
Code:
for (y=1;y<5;y++){
for (x=0;x<1000;x++){
if (x%y==0){ printf("this one: %d \n",x)}}}
how can i make the(x%y==0) condition to be checked for every y condtion ranging from
1 to 5
i mean how can it make it find every number that can be eveny divided to all number ranging from 1 to 5
thanks
-
Presumably by putting a semicolon ";" after your printf statement. Once you have that syntactically correct, your if statement will check 4000 different cases (y 1,2,3,4; x from 0 to 999).
-
Code:
for (y=1;y<6;y++){
for (x=0;x<1000;x++){
if (x%y==0){
printf("this one: %d \n",x);
}
}
}
If i understand you question correctly this should do it
edit:
as stated above, this will not check x=1000
-
Maybe you want something along these lines:
Code:
#include <stdio.h>
int main(void)
{
int x,y;
for (x=0;x<1000;x++)
{
int flag = 0;
for (y=1;y<=5;y++)
{
if (x%y)
{
flag = 1; /*found y that is not dividable by */
break;
}
}
if(flag == 0)
{
/* x is dividable by all y */
printf("this one: %d \n",x);
}
}
return 0;
}