C language: Enter a positive number less than 1000, output its square root, if not less than 1000 positive, re-enter

Source: Internet
Author: User
Tags square root

Enter a positive number less than zero from the keyboard , which requires the output of its square root (if the square root is not an integer, output its integer portion). Requires that the data be checked for a positive number that is less than zero after it is entered . If not, a re-entry is required.

Solution: Program:

#include <stdio.h>

#include <math.h>

#define M 1000

int main ()

{

int x, y;

printf ("Please enter a positive number less than%d x:", M);

scanf ("%d", &x);

while (X>M)

{

printf ("Input data does not meet the requirements, please re-enter a positive number less than%d x:", M);

scanf ("%d", &x);

y = sqrt (x);

}

y = sqrt (x);

printf (the integer portion of the square root of "%d" is:%d\n ", x, y);

return 0;

}

Result 1:

Please enter a positive number less than + x:Bayi

The integer part of the square root of Bayi is : 9

Please press any key to continue ...

Result 2:

Please enter a positive number less than + x:

The data entered does not meet the requirements, please re-enter a positive number less than + x:7612

The data entered does not meet the requirements, please re-enter a positive number less than + x:121

The integer part of the square root of the 121 is : One

Please press any key to continue ...


This article is from the "Rock Owl" blog, please be sure to keep this source http://yaoyaolx.blog.51cto.com/10732111/1741420

C language: Enter a positive number less than 1000, output its square root, if not less than 1000 positive, re-enter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.