I need a program that will print a square and cubes table. It would like this:
Number Square Cube
1 1 1
Once you get the square, couldn't you get the cube by multiplying the number *square? Or do you have to do a cube?
It should also print out the sum of the squares, the sum of the cubes, how many cubes were greater than 500, a message stating whether or not the sum of the squares exceeded 2,000.
Shouldn't it go something like this?
program SquareCubeTable;
var i, number, square, cube, sumsquare, sumcube: integer;
begin
for i := 1 to 15 do
begin
square := i * i;
cube:= number * square;
I don't know how to align it.
You would do the sum of the square and cubes like this?
begin
sum:= 0;
for i:= 1 to 15 do
sum := i*i + i;
writeln('sum of squares is ', sum)
if sumsquares > 2,000 then
writeln('Sum of squares was over 2,000 ')
begin
sum:= 0;
for I:= 1 to 15 do
sum:= number * square + 1;
writeln('sum of cubes is ', sum)
I don't how do this all in one program.
I wouldn' know about the greater than part
begin
sumsquare := 0;
sumcube := 0;
cubesgreater := 0;
for i := 1 to 15 do
begin
square := i * i;
cube := i * square;
sumsquare := sumquare + square;
cubesquare := cubesquare + cube;
if (cubesquare > 500) then
inc(cubesgreater);
end;
end.
This will do most of it for you. You need to print out the statements and tidy the code up.
Note that you must initialise your values before you use them.
This is the simplest code which I can offer.
{
In this program f is an integer variable which is used to format the
output. Formatting the output means much more than just allignment
of output. The expression :f:0 tells comuter(if f=13) to
reserve total length of 13 characters for number and 0 spaces for
numbers after decimal point. 0 because we know that cubes and squares of integers
are never in fractions. Try and see how different outputs come by
changing :f:0. If values of cubes and square grows larger simply
increase the value of f to format perfectly.
}
program square_cube;
uses crt;
var n,bigger_500,f : integer;
cube, square, sumcube, sumsquare : real;
begin
clrscr;
cube := 0; square := 0;
sumcube := 0; sumsquare := 0;
bigger_500 := 0; f := 13;
writeln('Number Square Cube');
for n := 1 to 15 do
begin
square := n * n;
cube := n * square;
sumsquare := sumsquare + square;
sumcube := sumcube + cube;
if cube > 500 then bigger_500 := bigger_500 + 1;
writeln(n:3,square:f:0,cube:f:0);
end;
writeln('--------------------------------');
writeln('Total',sumsquare:f-2:0,sumcube:f:0);
writeln;
if sumsquare > 2000 then writeln('The sum of squares is greater than 2000.')
else writeln('The sum of squares is not greater then 2000.');
writeln('The number of cubes greater than 500 = ',bigger_500);
writeln;
writeln('Press ENTER to continue.....');
readln;
end.
0
Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.
It works fine, but I can't get it to print. In fact, the table and the payroll
programs won't print either. I've used the 'uses printer' command in all of them.
This should work. Try it and report back. This is straight out of the TP 5.5 manual and assumes that your printer is connected to your parallel port LPT1.
0
kazooie21Author Commented:
I just wasn't logged into the network. I feel sheepish!!
0
Featured Post
Your question, your audience. Choose who sees your identityâ€”and your questionâ€”with question security.