Square and square root of numbers in a range – CSKC
Sign In

Search

Solved Problem #CPP#2049    siteicon   siteicon  

Problem Statement - Square and square root of numbers in a range

Write a c++ program to output the square and square roots of a number in a range where range begin variable is initialised in the variable ‘from’ and range end variable is initialised in the variable ‘to’.

Solution

TC++ #2049

 

×

Ask AI About This Code

Default Prompt that is passed along with the code is given below, You can write your own prompt if you so desire.



×

Test CPP

#include <math.h>
This library header will support use of sqrt function.

int from=10,to=20;
Here the range variable names declared and initialised as desired.

for(int i=from;i<=to;i++)
Here the range variable are used at appropriate places. The from variable for loop begin condition and to variable to check the loop closure condition.

cout<<i<<“x”<<i<<” = “<<i*i<<” “;
This line outputs the square by using the proper chaining of variables and string literals.

cout<<“sqrt(“<<i<<“)”<<” = “<<sqrt(i)<<endl;
This line print the square root with required suffix.

Common Errors

  • Care must be taken to chain the variables and string literals properly in the cout streams.


Share

Created: 31-Dec-2017 00:00 | Updated: 14-Dec-2018 00:01|