Oct 21, 2019, 04:54 PM

## News:

Latest Update on Rajini Movie  Enthiran / Endhiran - Rajini - The Robot

## Program to Find the perfect Square or Not

Started by thiruvasagamani, Sep 22, 2008, 05:07 PM

Go Down

#### thiruvasagamani

##### Sep 22, 2008, 05:07 PM
Test a number is perfect square or not

Code: [Select]
`#include <stdio.h>#include <conio.h>#include <math.h>int perfect square( int n){int a;a = sqrt( n); // a contain integer part of square root valuereturn ( a *a == n); // if a * a is 'n' , 'n' is perfect square}main(){int n, perfect square( int);printf(" enter any number \n");scanf("%d", &n);if( perfect square( n)) // is 'n' is perfect square ?printf(" perfect square \n");elseprintf(" not perfect square");getch();}`

o/p:
If you enter 'n' value as 49 output is perfect square

NOTE:
perfect square( 49) = returns non zero value to main() function i.e., true
perfect square( 35) = returns zero value to main() function i.e., false
Thiruvasakamani Karnan

#### haihello

#1
##### Nov 01, 2011, 11:16 PM
#include <stdio.h>
#include <conio.h>
#include <math.h>

int perfectsquare( int n)
{
int a;
a = sqrt( n); // a contain integer part of square root value
return ( a *a == n); // if a * a is 'n' , 'n' is perfect square
}

void main()
{
int n, perfectsquare( int);
printf(" enter any number \n");
scanf("%d", &n);
if( perfectsquare( n)) // is 'n' is perfect square ?
printf(" perfect square \n");
else
printf(" not perfect square");
getch();
}

Go Up

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:
Verification: