Monday, April 22, 2019

VALID PERFECT SQUARE

  • Problem Description

    Get a positive integer. Let N be the number of test cases.Check the number whether perfect square or not.Print TRUE when the integer is perfect square.If it is not, return FALSE.Describe it without using built-in-function.Input format: The input is verified whether the number is perfect square or not. Output format: Whether the input is perfect square then true is returned, else it should return false. EXPLANATION: Get a non-negative integer from the user. Check it whether it is perfect square or not by using arithmetic functions. Print True when it is valid perfect square integer. If the integer is not valid perfect square integer, then print False. Note: Do not use any inbuilt function. 
  • Test Case 1

    Input (stdin)
    34

    Expected Output
    FALSE
  • Test Case 2

    Input (stdin)
    121

    Expected Output
    TRUE
Solution

#include <stdio.h>

int main()
{
    int a, n;
    scanf("%d", &n);
    for(a = 0; a <= n; a++)
    {
        if (n == a * a)
        {
            printf("TRUE");
            return 0;
        }
    }
    printf("FALSE");
    return 0;
}

No comments:

Post a Comment

Parity

Problem Description Ram and Sita playing the parity game. Two types of parity are there. One is odd parity and next is even parity. Ram will...