Write a program to find the number of perfect squares between given two numbers A and B (both inclusive). A number is called a perfect square if it can be written as x*x for some integer x.
Example 1:
Input: 3 17
Output: 3
Solution.
#include<stdio.h>
int main()
{
int a, b;
scanf("%d%d", &a, &b);
int count=0;
int i, h;
for(i=1; i<=b; i++)
{
h=i*i;
if((a<=h)&&(b>=h))
count++;
}
printf("%d", count);
return 0;
}
No comments:
Post a Comment