CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Created by Swapnil More
/*
This code takes a number as an input and shows the perfect square present in the range from 1 to input number.
*/
// Challenge thread is in the comments section
#include <iostream>
#include <cmath>
using namespace std;
int square(int);
int main()
{
int num,sq,i;
cout<<"Enter a number: ";
cin>>num;
cout<<num<<endl;
if(num<0){
cout<<"Enter a positive number";
}
else{
cout<<"The perfect squares from 1 to "<<num<<" are ";
for(i=1;i<num;i++){
sq=square(i);
if(sq<num){
cout<<sq<<",";
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run