Squaring odd numbers - C++ Operator

C++ examples for Operator:Arithmetic Operator

Description

Squaring odd numbers

Demo Code

#include <iostream>
#include <iomanip>

int main() {//w w w .  j  a va2s . c  om
  int limit {};
  std::cout << "Enter the upper limit for squared odd numbers: ";
  std::cin >> limit;
  for (int i {1}; i <= limit; i += 2)
    std::cout << std::setw(4) << i << " squared is " << std::setw(8) << i * i << std::endl;
}

Result


Related Tutorials