How I can read from standard input 3!!! or 2/3 in Pascal?
factorials
Read it as a string, then parse it :)
How I can parse string? I don't know how pascal can make integer or longint from a part of string?
Well, that is one of the clues in the problem.
When you read a string "s" with: readln(s), then you can access all the elements of "s" as s[0], s[1], ...
from these values you can reconstruct the number.
When you read a string "s" with: readln(s), then you can access all the elements of "s" as s[0], s[1], ...
from these values you can reconstruct the number.
Try to google string functions in pascal, like Str, Val, Copy, Delete, Pos...
s[1],s[2] is an element of string, a part of number. But this element is also string type,so I can write this value to integer variable,so I can make a number in integer variable.
Example:
var s:string
a:integer;
begin
readln(s);
a:=s[2]; {s[2]is for example 3}
An error type mismatch occures. This is my problem whith this.
var s:string
a:integer;
begin
readln(s);
a:=s[2]; {s[2]is for example 3}
An error type mismatch occures. This is my problem whith this.
Here is part of my code, that gives you reading input.
Strr is a String type. N & K are LongInt.
ReadLn(Strr);
Poz:=Pos('!', Strr);
Val(Copy(Strr, 1, Poz - 1), n);
Delete(Strr, 1, Poz - 1);
k:=LengTh(Strr);
Strr is a String type. N & K are LongInt.
For your case to parse S[2] to Int type you should write this.
Val ( Copy ( S, 2, 1 ) , A );
Look at this site.
http://www.macdonald.egate.net/CompSci/Pascal/hstrings.html
http://www.macdonald.egate.net/CompSci/Pascal/hstrings.html
thanks a lot. Does Pascal have more functions and procedures like val,copy etc?
Don't know. Google it. :) I use Chr and Ord function for characters.