0
I wonder, why when I type in the program below that checks if the typed number is triangular, ie, is multiple of three consecutive numbers, as example 60 it prints two "NO" and a "YES", and when type 336 appear five "NO" and a "YES"?
#include <stdio.h>
int main(void)
{
int numero, i;
scanf("%d",&numero);
for(i = 1 ; i*(i+1)*(i+2)<=numero ; i++)
{
if(i*(i+1)*(i+2)==numero)
{
printf("SIM\n");
}
else
{
printf("NAO");
}
}
return 0;
}
(+1) or even
for(i = 1 ; i*(i+1)*(i+2)<numero ; i++){}
if(i*(i+1)*(i+2)==numero) { printf("SIM\n"); }else { printf("NAO"); }
– JJoao
(if is out of cycle)
– JJoao
the braces empty fooled me :)
– pmg
And the disarray of the comments also does not help anything :)
– JJoao
because of this I usually
/* void */
in the empty places:for (a, b, c) { /* void */ }
– pmg