I do not understand why the following C code does not work

1

I was working on c and looking at an old manual I found the following code that seemed simple.

int num=50, i;
for(i=1; i<=num; i++)
{
    if( !( num % i)) //esta es la línea que saltea
    {
        printf(“%d”, i);
    }
}

My answer when compiling is that they do not show anything, I do not know if I will miss a piece of code but in the manual it says that the if it has a non-zero value by default it enters into code and that value in the condition is the remainder of the number divided the counter denied. I would like to know what result it gives you when you compile it and why I do not get any data when compiling it (use CODEBLOCKs).

    
asked by Jay Alvarrez 09.12.2018 в 20:31
source

1 answer

2

The problem is the quotes and the "If".

Try this:

int num=50, i;
for(i=1; i<=num; i++)
{
if( !( num % i)) //esta es la linea que saltea
{
printf("%d\n", i);
}
}

By the way, what is printed are not the cousins, they are the numbers that divide num with remainder 0.

Complete program:

#include <stdio.h>

int main()
{
int num=50, i;
for(i=1; i<=num; i++)
{
if( !( num % i)) //esta es la linea que saltea
{
printf("%d\n", i);
}
}
}
    
answered by 09.12.2018 / 21:44
source