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