Program to Find the perfect Square or Not

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

previous topic - next topic
Go Down

thiruvasagamani

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 value
return ( 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");
else
printf(" 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

#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
 

Quick Reply

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:
Please leave this box empty:

Type the letters shown in the picture
Listen to the letters / Request another image

Type the letters shown in the picture:

shortcuts: alt+s submit/post or alt+p preview
IT Acumens | GinGly :: SMS Backup | Acumen :: Discussion Board | AshokPillar :: Hosting | CineBuzz :: Latest Cinema News | My Kids Diary :: Capture your kids magical moment
Copyright 2005 - 2017 :: IT Acumens :: All Rights Reserved.
ITAcumens Forum with 2 lakhs post running for 10 years - Powered by HostGator Dedicated Server