Monday 1 February 2016

NPTEL (Week - 1)

Nptel Week - 1(Assignment-1)

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.
Constraints:
Both A and B are positive. They both are less than 100,000.
Input: Two numbers A and B separated by a space
Output: Count of the number of perfect squares


Example 1:
Input: 3 10
Output: 2


Example 2:
Input: 16 70
Output: 5


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

}

No comments:

Post a Comment

How to install google-chrome in redhat without redhat subscription

Install google-chrome in redhat  Download the .rpm file of chrome https://www.google.com/chrome/thank-you.html?installdataindex=empty&st...