Write a C program
to check whether a given number is a perfect square number or not. or Write
a program to check whether a given number is a perfect square number
or not in C.
Program in C
Code:
/*Write a C program to check
whether a given number is a perfect square number or not. or Write a
program to check whether a given number is a perfect square number
or not Using C*/
#include<stdio.h>
#include<math.h>
int main()
{
int num;
printf("Enter a number:");
scanf("%d",&num);
int count=0;
double sqr=sqrt(num);
if(sqr-floor(sqr)==0)
printf("It is a Perfect Square");
else
printf("It is not a Perfect Square ");
}
Input/Output:
Enter a number:
36
It is a Perfect Square
Write a C++ program
to check whether a given number is a perfect square number or not. or Write
a program to check whether a given number is a perfect square number or not in C++.
Program in C++
Code:
/*Write a C++
program to check whether a given number is a perfect square number or
not. or Write a program to check whether a given number is a perfect
square number or not using C++*/
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int num;
cout<<"Enter a number:";
cin>>num;
int count=0;
double sqr=sqrt(num);
if(sqr-floor(sqr)==0)
cout<<"It is a Perfect Square";
else
cout<<"It is not a Perfect Square ";
}
Input/Output:
Enter a number:
225
It is a Perfect Square
Write a JAVA
program to check whether a given number is a perfect square number or
not. or Write a program to check whether a given number is a perfect
square number or not in Java.
Program in Java
Code:
/*Write a JAVA
program to check whether a given number is a perfect square number or
not. or Write a program to check whether a given number is
a perfect square number or not using Java*/
import java.util.Scanner;
public class PerfectSquareNumberOrNot {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int num;
System.out.println("Enter a number:");
num=cs.nextInt();
int count=0;
double sqr=Math.sqrt(num);
if(sqr-Math.floor(sqr)==0)
System.out.println("It is a Perfect Square");
else
System.out.println("It is not a Perfect Square ");
cs.close();
}
}
}
Input/Output:
Enter a number:
33
It is not a Perfect Square
Write a PYTHON to check
whether a given number is a perfect square number or not. or Write a
program to check whether a given number is a perfect square number or not in
Python.
Program in Python
'''Write
a Python program to check whether a given number is a perfect square
number or not. or Write a program to check whether
a given number is a perfect square number or not using Python '''
import math
num=int(input("Enter a number:"))
sqr=math.sqrt(num)
if sqr-math.floor(sqr)==0:
print("It is a Perfect Square")
else:
print("It is not a Perfect Square")
Input/Output:
Enter a number:1000
It is not a Perfect Square
0 Comments
Please do not Enter any spam link in the comment box