Skip to main content
deleted 2 characters in body
Source Link
chux
  • 33.7k
  • 2
  • 38
  • 92

Overflow

i*i can overflow (given a pause every 24, it would take a lot of enters).

To prevent overflow, use a wider type for the multiplicaiton.

#include <inttypes<stdint.h>

// printf("%10d%10d\n", i, i*i);
printf("%10d %10lld\n", i, 1LL*i*i);
// or better
printf("%10d %10jd\n", i, (intmax_t)i*i);

Overflow

i*i can overflow (given a pause every 24, it would take a lot of enters).

To prevent overflow, use a wider type for the multiplicaiton.

#include <inttypes.h>

// printf("%10d%10d\n", i, i*i);
printf("%10d %10lld\n", i, 1LL*i*i);
// or better
printf("%10d %10jd\n", i, (intmax_t)i*i);

Overflow

i*i can overflow (given a pause every 24, it would take a lot of enters).

To prevent overflow, use a wider type for the multiplicaiton.

#include <stdint.h>

// printf("%10d%10d\n", i, i*i);
printf("%10d %10lld\n", i, 1LL*i*i);
// or better
printf("%10d %10jd\n", i, (intmax_t)i*i);
Source Link
chux
  • 33.7k
  • 2
  • 38
  • 92

Overflow

i*i can overflow (given a pause every 24, it would take a lot of enters).

To prevent overflow, use a wider type for the multiplicaiton.

#include <inttypes.h>

// printf("%10d%10d\n", i, i*i);
printf("%10d %10lld\n", i, 1LL*i*i);
// or better
printf("%10d %10jd\n", i, (intmax_t)i*i);