Program to find Square number between the range
Question
Write a program to find the square number between the range. Get the range from the user.
LOGIC
- To efficiently find the range we are using sqrt function.
- First, find the square root of starting value( 20 -> 4.47 )
- It is converted to integer form( 4.47 ->4)
- Square of this number must be greater or equal to start(st)
- Then, the number is incremented by 1 and the same process repeated.
Program
#include<stdio.h> #include<math.h> void main() { int st, ed,s,e,sq,i; printf("enter start and end"); scanf("%d%d",&st,&ed); s = sqrt(st); e = sqrt(ed); for (i=s;i<=e;i++) { sq= i*i; // square of i if(sq>=st&&sq<=ed) //check range 20 t0 100 printf("%d\n",sq); } </pre>