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.

Square number between range

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>

 

Follow For Instant Updates

Join WhatsApp Group: link
Join our Telegram Channel: link
Like our Facebook Page:  link
Subscribe to our Youtube channel: link

Sree Hari Sanjeev

The founder of Wisdom Overflow. Software Developer at Zoho Corporation.
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x