Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Converting STRING to INTEGER/REAL....

Posts: 10Member
I need to write a program that can find and print all the 3-digit palindromic prime numbers. Palindromic numbers are numbers that are the same forward and backword.

Since there is no pattern in these numbers, I'm just gonna test every number from 100 to 999 with a FOR-TO-DO loop. I need to test palindromes of each other.

So basically is there any way to give a variable a string value such as '343' and convert it to the integer, 343 or the real, 343.0?

Any help would be greatly appreciated.
· ·

• Posts: 6,349Member
: I need to write a program that can find and print all the 3-digit palindromic prime numbers. Palindromic numbers are numbers that are the same forward and backword.
:
: Since there is no pattern in these numbers, I'm just gonna test every number from 100 to 999 with a FOR-TO-DO loop. I need to test palindromes of each other.
:
: So basically is there any way to give a variable a string value such as '343' and convert it to the integer, 343 or the real, 343.0?
:
: Any help would be greatly appreciated.
:
Use the Val() procedure for the conversion. More info in the help files.
· ·
• Posts: 9Member
: I need to write a program that can find and print all the 3-digit palindromic prime numbers. Palindromic numbers are numbers that are the same forward and backword.
:
: Since there is no pattern in these numbers, I'm just gonna test every number from 100 to 999 with a FOR-TO-DO loop. I need to test palindromes of each other.
:
: So basically is there any way to give a variable a string value such as '343' and convert it to the integer, 343 or the real, 343.0?
:
: Any help would be greatly appreciated.
:[code][size=2]
:program palindrom;
:uses crt;
:var a:array[1..200]of string;
: k,inv,nr,i:longint;
:begin
: clrscr;
: k:=0;
: for i:=100 to 999 do
: begin
: nr:=i;
: inv:=0;
: while nr<>0 do
: begin
: inv:=inv*10 + nr mod 10;
: nr:=nr div 10;
: end;
: if (inv=i) then
: begin
: k:=k+1;
: str(i,a[k]); {str-function converts ordinal to string}
: {sintax : str(,) }:
:
: {val-function converts string to ordinal}
: {sintax : val(,
: ,}
: end;
: end;
:
:end.
[/size][/code]

· ·