Primes
Given two integers N and M (N <= M), output all the prime numbers between N and M inclusive, one per line.
N and M will be positive integers less than or equal to 1,000,000,000.
The difference between N and M will be less than or equal to 5,000,000.
Bills Bills Bills
A gas company has a monthly billing rate based on consumption by its customers. The rate structure is given as follows:
___________________________________________________
For the first 10m3 or less $6.59 (minimum bill)
For the next 20m3 23.73 cents/m3
For the next 55m3 22.71 cents/m3
For the next 85m3 21.78 cents/m3
For the next 170m3 20.85 cents/m3______
Write a program that will process the customers' bills. For each customer, the program should read an account number 0 <= A <= 99999 and two meter readings 0 <= M1, M2 < 10000. M1 represents the reading at the beginning of the month while M2 represents the reading at the beginning of the next month. The first line of input will be the account number. The second line of input will be M1 followed by a space then M2. The input will be terminated if and only if a negative account number is entered.
Note: There are situations where the final reading may be less than the initial reading. For example, the initial reading might be 9980 while the final reading is 0015 indicating a consumption during the month of 35m3 because the meter has 'rolled over'.
Need Help In Few Questions [Pascal]
Started by JP16.1470, Nov 11 2008 06:08 PM
7 replies to this topic
#1
Posted 11 November 2008 - 06:08 PM
|
|
|
#2
Posted 12 November 2008 - 07:24 AM
What do you have so far for these programs?
#3
Posted 12 November 2008 - 08:37 AM
I got nothin for the bills question but for the prime question i got this:
It works but it gives me the first 100 primes and doesnt wrk on the input of the user so if i input "4" then it still prints out all the first 100 primes when it should only output the first 4 prime numbers
Program Prime ;
{ a program to print out all primes up to 1000
using the Sieve of Eratosthenes.}
uses crt;
CONST
N = 100 ;
Var
P : Array [1 .. N] of Boolean ;
i,j,m : Word ;
begin
clrscr
for i := 1 TO N do
P[i] := TRUE ;
m := trunc(sqrt(N)) ;
for i := 2 to m do
if P[i] then
for j := 2 to N DIV i do
P[i * j] := FALSE ;
for i := 1 to N do
if P[i] then
writeln(i:4) ;
end.
It works but it gives me the first 100 primes and doesnt wrk on the input of the user so if i input "4" then it still prints out all the first 100 primes when it should only output the first 4 prime numbers
#4
Posted 12 November 2008 - 10:04 AM
You need to check the value of the prime to see if it is larger than the minimum value before calling writeln.
#5
Posted 12 November 2008 - 02:12 PM
what do u exactly mean? can you edit the code..and fix it? PLZ THX
#6
Posted 12 November 2008 - 02:27 PM
for i := 1 to N do
if P[i] and (i>= Min) then
writeln(i:4) ;
#7
Posted 12 November 2008 - 05:05 PM
In:
that it says "invalid type" on "Min".........can you please do the whole program and put it? PLZ! THX! :)
(i>= Min)
that it says "invalid type" on "Min".........can you please do the whole program and put it? PLZ! THX! :)
#8
Posted 12 November 2008 - 05:33 PM
I am willing to help you, but not write the program for you. You need to get the minimum value into your program (as an integer) and use the comparison. Right now your program doesn't have ANYTHING that deals with the minumum value requirement.


Sign In
Create Account

Back to top









