Wednesday, August 9, 2017

Write a c++ program that tells the user whether a number is a perfect square or not.

/*
For more exercises,
visit shegertech.blogspot.com
or
shegertech.com

Author: Eyasu M.
Email: eyasu@india.com
*/

#include <iostream>
using namespace std;

int main(){

int x=0;
bool flag = false;

cout <<"Enter a number : ";
cin>>x;

cout<<endl;

for(int i=1;i<x;i++){
if(i*i == x){
flag= true;
}

}
if(flag){
cout<<"Bingo ! "<<x <<" is a perfect square."<<endl;
}
else{
cout<<x<<" is not a perfect square."<<endl;
}

return 0;
}
Share: