Wednesday, 25 July 2018

Question: Tile Game
In connection to the National Mathematics Day celebration, the Regional Mathematical Scholars Society had arranged for a Mathematics Challenge Event where school kids participated in large number. Many interesting math games were conducted, one such game that attracted most kids was the tile game where the kids were given 'n' square tiles of the same size and were asked to form the largest possible square using those tiles.

Help the kids by writing a program to find the area of the largest possible square that can be formed, given the side of a square tile (in cms) and the number of square tiles available.

Input Format:
First line of the input is an integer that corresponds to the side of a square tile (in cms).
Second line of the input is an integer that corresponds to the number of square tiles available.

Output Format:
Output should display the area of the largest possible square that can be formed (in square cms) with the available tiles.
Refer sample input and output for formatting specifications.
[All text in bold corresponds to input and rest corresponds to output.]

Sample Input and Output :
Enter the side in cm of a square tile
5
Enter the number of square tiles available
8
Area of the largest possible square is 100sqcm



SOLUTION:
#include<stdio.h>
int main()
{
    int l,n,i=1,m=0,a;
    printf("Enter the side in cm of a square tile");
    scanf("%d",&l);
    printf("\nEnter the number of square tiles available");
    scanf("%d",&n);
    while(i*i <= n)
    {
        m=i*i;
        i++;
    }
    a=m*(l*l);
    printf("\nArea of the largest possible square is %dsqcm",a);
    return 0;
}

3 comments:

  1. This is wrong.by using this code we can get 36 only

    ReplyDelete
  2. That's because you're writing a=m*(i*i) instead of a=m*(l*l)

    ReplyDelete
  3. there is few error with the above code; the correct code for the given problem is

    #include

    int main() {
    float squareSide;
    int number;
    float SqArea;
    int i = 1;
    int HighestSquare;
    int m = 0;
    int x;
    float result;

    scanf("%f", &squareSide);
    scanf("%d", &number);
    SqArea = squareSide * squareSide;

    while (i * i <= number) {
    m = i * i;
    ++i;
    }

    if (m != number) {
    x = number - m;
    HighestSquare = number - x;
    result = SqArea * HighestSquare;
    printf("%.1f\n", result);
    } else {
    result = SqArea * number;
    printf("%.1f\n", result);
    }

    return 0;
    }

    ReplyDelete

Random password generator in Java

       Random password generator in Java Source code: mport java.io.*; import java.util.*; public class Main { public static void main(Str...