Question about square numbers (perfect squares)

Asked

Viewed 30 times

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 whether sqrt(numero) is a whole?

  • 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

  • But it is not checking whether the number given is integer, but rather its square root.

  • 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.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.