You might transform:
bool estCarre(int a)
{
for (int i = 1; i <= a; i++)
{
if (i*i==a){
return true;
}
if(i*i>a){
return false;
}
}
return false;
}
into
bool estCarre(int a, int i = 1)
{
// Loop content:
if (i * i == a) {
return true;
}
if (i * i > a) {
return false;
}
// increment + loop condition + (recursive) loop
if (i + 1 < a) {
return estCarre(a, i + 1);
}
// outside loop
return false;
}
solved Write a function which checks if a number is a square with recursive function