Coding Question 3 Free Section

Perfect Square or not Program

C

```/*C program to check number is perfect square or not.*/

#include <stdio.h>
#include <math.h>

int main()
{
int num;
int iVar;
float fVar;

printf("Enter an integer number: ");
scanf("%d",&num);

fVar=sqrt((double)num);
iVar=fVar;

if(iVar==fVar)
printf("%d is a perfect square.",num);
else
printf("%d is not a perfect square.",num);

return 0;
}```

Java

`// Java program to find if x is a// perfect square.class PI {static boolean isPerfectSquare(double x) {// Find floating point value of// square root of x.double sr = Math.sqrt(x);// If square root is an integerreturn ((sr - Math.floor(sr)) == 0);}// Driver codepublic static void main(String[] args) {double x = 2500;if (isPerfectSquare(x))System.out.print("Yes");elseSystem.out.print("No");}}// This code is contributed by Anant Agarwal.`

8 comments on “Coding Question 3 Free Section”

• shriya

import java.util.Scanner;
public class PerfectSq
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
boolean flag = false;
for(int i=1;i0))
{
System.out.println(“perfect Square”);
}
else
{
System.out.println(“not a perfect Square”);
}
}
}

• shriya

import java.util.Scanner;
public class PerfectSq{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
boolean flag = false;
for(int i=1;i0)){
System.out.println(“perfect Square”);
}
else{
System.out.println(“not a perfect Square”);
}
}
}

• Piyush

from math import sqrt
a = int(input(“enter num ::”))

if(sqrt(a) % 2 ==0 or sqrt(a) % 2 ==1 ):
print(“Perfect Square”)
else:
print(“Not perfect Square”)

• ketan kokate

#include
#include
using namespace std;

int main()
{
int num,square=0;
cout<>num;
for(int i=1;i<=num;i++)
{
if(i*i==num)
{
square=1;
}
else{}
}
if(square==1)
{
cout<<"square";
}
else{cout<<"not";}

}

• Manjunath

In python,
x=int(input())
for i in range(1,n+1):
if i*i==n:
print(‘true’)
else;
print(‘false’)

• anusha anusha

def is_perfect_square(n):
x = n // 2
y = set([x])
while x * x != n:
x = (x + (n // x)) // 2
if x in y: return False
return True

print(is_perfect_square(8))

• vinila

give us tcs verbal questions previous year papers

• Gvs Saisumanth

#include
#include

int main()
{
int num;
int iVar;
float fVar;

printf(“Enter an integer number: “);
scanf(“%d”,&num);
iVar=num;

fVar=sqrt((double)num);
iVar=fVar;

if(iVar==fVar)
printf(“%d is a perfect square.”,num);
else
printf(“%d is not a perfect square.”,num);

return 0;
}