Perfect Squares

Write a C program to find number of perfect squares between A and B (both inclusive)?

Done. Wrote it.

But I’m not sharing it.

2 Likes

int(sqrt(B)) - int(sqrt(A)) should give the answer.

1 Like

#include <stdio.h>
int main()
{
int a,b;
int i,j;
scanf("%d",&a);
scanf("%d",&b);
for(i=a;i<=b;i++)
{
for(j=1;j<i;j++)
{
if(i==j*j)
printf("%d",i);
}
}
return 0;
}

Simply sqrt(B)-sqrt(A-1).

can you give some hint about the logic?

@mitalishri , you don’t understand it, do you ? If you had asked the question in a better way rather than " Write a code to do blablabla " , we might have helped you. Edit your question. Explain what you tried, and where you failed. Then, someone might help you.

1 Like