c - Can someone explain why my for loop stops at the wrong place -


sorry if dumb mistake i'm beginner. i'm answering question in book c programming modern approach. asks print squares between 1 , number given.

this original code:

#include <stdio.h>  int main(void) {   int n, i;    printf("enter number: ");   scanf ("%d", &n);    (int = 2; <= n ; += 2) {     printf("%d %d\n", * i, n);   }    return 0; } 

the problem stop once hits ten thousand divided "n" inside loop:

for (int = 2; <= n / 10 ; += 2) {   printf("%d %d\n", * i, n); } 

can explain why happens

the loop check should i * <= n if want squares stop before n

  (int = 2; * <= n ; += 2) { 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -