0
I need to make an algorithm that reads any number and checks if it’s quadrangular. If it is, show the next 10 quadrangular after it. If it is not, inform.
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
int main() {
using namespace std;
int valor, soma=0, fator, i;
int ii;
cout << ("Informe um numero: ");
cin >> valor;
for(i=1; soma < valor; i+=2)
soma += i;
(fator = ((i+1) / 2) - 1);
i++;
if ((fator*fator) == valor)
cout << (" eh quadrangular\n");
else cout << ("nao eh quadrangular");
return 0;
}
I am unable to assemble the repeating structure to repeat the 10 numbers in front of the typed.
Instead of
sqrt(numero)*sqrt(numero)==numero
, why not check whethersqrt(numero)
is a whole?– Woss
I just tried, I think it’s not right because the number I type is always whole, what I want is for you to show the numbers on the screen, show only the ones that have exact root
– diogoBRRN
But it is not checking whether the number given is integer, but rather its square root.
– Woss
I think I got it, I just assigned the square root of the number to an integer variable. Now I just need to make the numbers repeat, have the exact root.
– diogoBRRN