c++ - Printing a value makes the program work? -


#include <iostream> #include <cstdio>  using namespace std;  bool numar(unsigned long long n) {     return (n > 99) && ((n % 100) == 25); }  int main() {     freopen("numere.in", "r", stdin);     freopen("numere.out", "w", stdout);      int cnt = 0;      unsigned long long n, a, nblabla, n;      while (scanf("%d", &n) == 1)     {         if (numar(n))         {             = (n - 25) / 100;              cout << a; // son of *****.              (n = 1; true; n++)             {                 nblabla = n * (n + 1);                  if (nblabla > a)                     break;                 else if (nblabla == a)                 {                     cnt++;                 }             }         }     }      printf("%d", cnt);      return 0; } 

simply, if comment line (cout << a;), program stops working. if leave there, works.
i'm using code::blocks, gnu gcc.

this checks if number square of number ends digit 5. (base 10) (i not allowed use square roots)

before asking, no, isn't homework. submission subject of online contest.

can tell me why happening?

with %d format, scanf try read pointer int. &n pointer unsigned long long. leads undefined behavior, reason of strange result.

the right format %llu.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -