# 4.1#4

4. write a program that reads a positive integer N and then prints an "N times table" containing values up to N * N.

for example,if the program reads the value 5, it should print

5*1 = 5
5*2 = 10
5*3 = 15
5*4 = 20
5*5 = 25

i wrote program but it 's not working could help me? Please.

uses crt;
var m,n : integer;
begin
clrscr;
for n := 1 to 5 do;
writeln( m * n);
end.

• Close, just remove the second ReadLn() because you are only to give one number in the question and change it from "5" to "m" (see bold below) as it will not always be "5" entered. Also, I have added some lines for clarity (good programming habits) and to match your output in the question.

[code]
uses crt;
var m,n : integer;
begin
clrscr;
write('Enter a number to calculate it's times table: ');
for n := 1 to [b]m[/b] do;
writeln(n,'*',m,' = ', m * n);
end.
[/code]
• : Close, just remove the second ReadLn() because you are only to give
: one number in the question and change it from "5" to "m" (see bold
: below) as it will not always be "5" entered. Also, I have added some
: lines for clarity (good programming habits) and to match your output
: in the question.
:
: [code]:
: uses crt;
: var m,n : integer;
: begin
: clrscr;
: write('Enter a number to calculate it's times table: ');
: for n := 1 to [b]m[/b] do;
: writeln(n,'*',m,' = ', m * n);
: end.
: [/code]:
:
The semicolon after the word [b]do[/b] does not belong there. It makes the for loop a null loop.
• : : Close, just remove the second ReadLn() because you are only to give
: : one number in the question and change it from "5" to "m" (see bold
: : below) as it will not always be "5" entered. Also, I have added some
: : lines for clarity (good programming habits) and to match your output
: : in the question.
: :
: : [code]: :
: : uses crt;
: : var m,n : integer;
: : begin
: : clrscr;
: : write('Enter a number to calculate it's times table: ');
: : for n := 1 to [b]m[/b] do;
: : writeln(n,'*',m,' = ', m * n);
: : end.
: : [/code]: :
: :
: The semicolon after the word [b]do[/b] does not belong there. It
: makes the for loop a null loop.
:
Thanks bro for your help. God bless you.
• : : : Close, just remove the second ReadLn() because you are only to give
: : : one number in the question and change it from "5" to "m" (see bold
: : : below) as it will not always be "5" entered. Also, I have added some
: : : lines for clarity (good programming habits) and to match your output
: : : in the question.
: : :
: : : [code]: : :
: : : uses crt;
: : : var m,n : integer;
: : : begin
: : : clrscr;
: : : write('Enter a number to calculate it's times table: ');
: : : for n := 1 to [b]m[/b] do;
: : : writeln(n,'*',m,' = ', m * n);

: : : end.
: : : [/code]: : :
: : :
: : The semicolon after the word [b]do[/b] does not belong there. It
: : makes the for loop a null loop.
: :
: Thanks bro for your help. God bless you.
:
there is one problem. when i enter a 5 it only time 5*5 = 25 it should times by 1 to 5 like this 5*1 = 5
5*2 =10
5*3 =15
5*4 =20
5*5 =25
• : : : : Close, just remove the second ReadLn() because you are only to give
: : : : one number in the question and change it from "5" to "m" (see bold
: : : : below) as it will not always be "5" entered. Also, I have added some
: : : : lines for clarity (good programming habits) and to match your output
: : : : in the question.
: : : :
: : : : [code]: : : :
: : : : uses crt;
: : : : var m,n : integer;
: : : : begin
: : : : clrscr;
: : : : write('Enter a number to calculate it's times table: ');

: : : : for n := 1 to [b]m[/b] do;
: : : : writeln(n,'*',m,' = ', m * n);
:
: : : : end.
: : : : [/code]: : : :
: : : :
: : : The semicolon after the word [b]do[/b] does not belong there. It
: : : makes the for loop a null loop.
: : :
: : Thanks bro for your help. God bless you.
: :
: there is one problem. when i enter a 5 it only time 5*5 = 25 it
: should times by 1 to 5 like this 5*1 = 5
: 5*2 =10
: 5*3 =15
: 5*4 =20
: 5*5 =25
:
[color=Orange]
here try this... it works for me[/color]

[code]var
n,m:integer;
begin
clrscr;
m:=n;
for n:=1 to n do
writeln(m,' x ',n,' = ',n*m);
end.[/code]

• : [code]
: uses crt;
: var m,n : integer;
: begin
: clrscr;
: write('Enter a number to calculate it's times table: ');
: for n := 1 to [b]m[/b] do[red]; { here's your problem }[/red]
: writeln(n,'*',m,' = ', m * n);
:
: end.
:[/code]
:
:
: there is one problem. when i enter a 5 it only time 5*5 = 25 it
: should times by 1 to 5 like this 5*1 = 5
: 5*2 =10
: 5*3 =15
: 5*4 =20
: 5*5 =25
:

You still have the semicolon after the word [b]do[/b]; That semicolon terminates the [b]do[/b] loop, so there is nothing in the loop. The [b]writeln[/b] that follows stands by itself. It is not in the loop. It executes once with the values n = 5, m = 5, the value of n being left over from the loop. Get rid of the semicolon and your program will work, except...
[code]
write('Enter a number to calculate it's times table: ');
[/code]
should be
[code]
write('Enter a number to calculate it''s times table: ');
[/code]
As is, the apostrophe in the word "it's" delimits the string constant. It needs to be a double apostrophe so that the compiler does not see it as a delimiter. Did your compiler not give you an error?

• : : [code]:
: : uses crt;
: : var m,n : integer;
: : begin
: : clrscr;
: : write('Enter a number to calculate it's times table: ');
: : for n := 1 to [b]m[/b] do[red]; { here's your problem }[/red]
: : writeln(n,'*',m,' = ', m * n);
: :
: : end.
: :[/code]:
: :
: :
: : there is one problem. when i enter a 5 it only time 5*5 = 25 it
: : should times by 1 to 5 like this 5*1 = 5
: : 5*2 =10
: : 5*3 =15
: : 5*4 =20
: : 5*5 =25
: :
:
: You still have the semicolon after the word [b]do[/b]; That
: semicolon terminates the [b]do[/b] loop, so there is nothing in the
: loop. The [b]writeln[/b] that follows stands by itself. It is not
: in the loop. It executes once with the values n = 5, m = 5, the
: value of n being left over from the loop. Get rid of the semicolon
: and your program will work, except...
: [code]:
: write('Enter a number to calculate it's times table: ');
: [/code]:
: should be
: [code]:
: write('Enter a number to calculate it''s times table: ');
: [/code]:
: As is, the apostrophe in the word "it's" delimits the string
: constant. It needs to be a double apostrophe so that the compiler
: does not see it as a delimiter. Did your compiler not give you an
: error?
:
:
:
Thank you. ProgramHeaven rock. god bless you.

• : As is, the apostrophe in the word "it's" delimits the string
: constant. It needs to be a double apostrophe so that the compiler
: does not see it as a delimiter. Did your compiler not give you an
: error?
:

Thanks Actor, I think I must have been half asleep on this reply. lol.