Menu Close

Find the number of silver rectangles [FTC]

Suresh have “N” rectangles. A rectangle is Silver if the ratio of its sides is in between [1.6, 1.7], both inclusive. Your task is to find the number of silver rectangles.

Constraints:
1 <-N <-10^5
1 <- W, H <- 10^9

Input Format:
First line: Integer “N” denoting the number of rectangles Each of the “N” following lines:
Two integers W, H denoting the width and height of a rectangle

Output Format.
Print the output in a single line contains find the number of Silver rectangles.

Sample Input:
5
10 1
165 100
180 100
170 100
160 100

Sample Output:
3

Explanation:
There are three Silver rectangles: (165, 100), (170, 100), (160, 100)

#include<stdio.h>
#include<math.h>
int main()
{
  float n,i,width,height;
  printf("Enter the N triangle:  ");
  scanf("%f",&n);
  int count=0;
  printf("Enter the width and height of triangle:\n");
  for(i=0;i<n;i++)
  {
    scanf("%f %f",&width,&height);
    if(width/height>=1.6 && width/height<=1.7)
        ++count;
    else if(height/width >=1.6 && height/width<=1.7)
        ++count;
  }
  printf("Total Silver rectangles are %d \n",count+1);
  return 0;
}

ScrShot

Input:
Enter the N triangle: 5
Enter the width and height of triangle:
10 1
165 100
180 100
170 100
160 100
Output:
Total Silver rectangles are 3

Input:
Enter the N triangle: 3
Enter the width and height of triangle:
50 100
200 300
120 190
Output:
Total Silver rectangles are 1

Input:
Enter the N triangle: 4
Enter the width and height of triangle:
250 600
300 210
150 180
100 200
Output:
Total Silver rectangles are 1