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
Post a Comment