You’ve been given an assorted set of gears. Each gear has a different number of teeth – the notches on a gear that interlock with notches on another gear to transmit speed. You have a couple of belts one coupled to an input and the other for the output. You are given the rpm of the input belt Si and a minimum value So (where So > Si) so that you can increase the speed via a system of gears as shown above
You need to figure out all the possible pairs of gears that can be used to achieve an output rpm >= So.
Input
The input is specified in a file containing test-cases.
• The first line contains the number of gears that are available to you, g.
• The next line contains g numbers indicating the number of teeth on each gear, separated by spaces.
• The next line contains the number of test cases – n
o This is followed by n test cases. Each test case is specified by 2 speed values on a single line. (So here the first test case specifies that you need to design a gear-system that increases Si = 50 rpm to a value above 200 rpm)
7
20 10 4 6 40 25 100
2
50 200
35 75

Output
9
15

E.g. for raising the speed from 50 to 200, any of the following 9 pairs can be used
[100, 6] [40, 6] [25, 6] [25, 4] [20, 4] [40, 4] [100, 4] [100, 20] [100, 10]

Rules :
• Your program must accept a string as a command line argument. It should then proceed to open the file of that name in the same/current directory, which contains one or more test cases. Output should be printed to console via printf (or equivalent).
• The program will not expect any user input. Please test your program for compile / run time errors before submitting.
• You may submit multiple submissions – strive for solutions that are elegant, memory and time efficient.
• The time limit if specified is for all the test cases to be executed; the time limit is NOT per test case
* We would compile your program into an executable and run it (e.g. c:\>X.exe TestCases.txt)

You’ve been given an assorted set of gears. Each gear has a different number of teeth – the notches on a gear that interlock with notches on another gear to transmit speed. You have a couple of belts one coupled to an input and the other for the output. You are given the rpm of the input belt Si and a minimum value So (where So > Si) so that you can increase the speed via a system of gears as shown above
You need to figure out all the possible pairs of gears that can be used to achieve an output rpm >= So.
Input
The input is specified in a file containing test-cases.
• The first line contains the number of gears that are available to you, g.
• The next line contains g numbers indicating the number of teeth on each gear, separated by spaces.
• The next line contains the number of test cases – n
o This is followed by n test cases. Each test case is specified by 2 speed values on a single line. (So here the first test case specifies that you need to design a gear-system that increases Si = 50 rpm to a value above 200 rpm)
7
20 10 4 6 40 25 100
2
50 200
35 75

Output
9
15

E.g. for raising the speed from 50 to 200, any of the following 9 pairs can be used
[100, 6] [40, 6] [25, 6] [25, 4] [20, 4] [40, 4] [100, 4] [100, 20] [100, 10]

Rules :
• Your program must accept a string as a command line argument. It should then proceed to open the file of that name in the same/current directory, which contains one or more test cases. Output should be printed to console via printf (or equivalent).
• The program will not expect any user input. Please test your program for compile / run time errors before submitting.
• You may submit multiple submissions – strive for solutions that are elegant, memory and time efficient.
• The time limit if specified is for all the test cases to be executed; the time limit is NOT per test case
* We would compile your program into an executable and run it (e.g. c:\>X.exe TestCases.txt)

I want this to be implemented in C.

Not really sure what your question is...well beside the main homework question..

I want this program statement given to be implemented in C.

Comments

I have solved this in asp.net using C#
Let first create the .aspx page

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="BIQ_005_Accelerator._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    
    
    <form id="form1" runat="server">
    <asp:Label ID="lblip" runat="server" Text="I/P"></asp:Label>
&nbsp;&nbsp;&nbsp;
    <asp:TextBox ID="txtip" runat="server"></asp:TextBox>
    <br />
    <br />
    <asp:Label ID="lblop" runat="server" Text="O/P"></asp:Label>
&nbsp;&nbsp;&nbsp;
    <asp:TextBox ID="txtop" runat="server"></asp:TextBox>
    <br />
    <br />
    <asp:Button ID="btnshow" runat="server" onclick="btnshow_Click" Text="SHOW" />
&nbsp;&nbsp;&nbsp;
    <asp:Label ID="Label3" runat="server" Visible="False"></asp:Label>
    </form>
    
    
</body>
</html>

Now the C# code :

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace BIQ_005_Accelerator
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnshow_Click(object sender, EventArgs e)
        {
            int[] rpm = {20,10,4,6,40,25,100 };
            Label3.Visible = true;
            Label3.Text =Convert.ToString( rpm.Length);
            int count = 0;
            int j = 0,i=0;
            
                while (i < rpm.Length - 1)
                {
                double ipval = Convert.ToDouble(txtip.Text);
                double opval=Convert.ToDouble(txtop.Text);
                double divval = Convert.ToDouble(rpm[i]) / Convert.ToDouble(rpm[j]);
                double grval = ipval / divval;
                if (grval > opval)
                {
                    count++;
                    
                }
                i++;
                if (i == rpm.Length - 1)
                {
                   
                    if (j >= rpm.Length - 1)
                    {
                       break;
                    }
                    j++;
                    i = 0;
                }
            }
            
            Label3.Text = Convert.ToString(count);

        }
    }
}

From : Maqsod Shah ([email removed])

Edited 5 Years Ago by WaltP: Added CODE Tags, and removed email

Comments
this is the C subform
This article has been dead for over six months. Start a new discussion instead.