Jump to content

2 simple pascal problem help!pls

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
rlpp

rlpp

    Newbie

  • Members
  • Pip
  • 2 posts
i am trying to do these problems but i am a beginner and i don't get them
1,
I have to find the leap year.
Var

iPrime,range,i,y: integer;
prime: boolean;
Begin
clrscr;
readln(i);
for y:=1 to i do
Begin
readln(iprime);
if (iprime=100) then
prime := false
else if iprime mod 4 = 0 then prime := true;

end;
for y:= 1 to i do
begin
if prime = true then writeln ('1')
else writeln('0');
end;
readln;
can anyone tell me why is it not working? and if possible can anyone give me a solution to the problem?


2, there is something wrong with this program too,
Given N characters , 'A' to'F', Print how many A has, then B, then C and so on.
something would be
input
2
A
B
out put
1 A
1 B
0 C
0 D
0 E
0 F
Var
e,f,g,h,i,j,u:integer;
c:char;

begin
clrscr;
e:=0;
f:=0;
g:=0;
h:=0;
i:=0;
j:=0;
u:=0;


readln(a);
for d := 1 to a do
readln(c);
case c of
'a': e:=e+1;
'b': f:=f+1;
'c': g:=g+1;
'd': h:=h+1;
'e':i:=i+1;
'f':j:=j+1
else
u:=u+1;
end;
writeln(e);
writeln(f);
writeln(g);
writeln(h);
writeln(i);
writeln(j);
writeln(u);
readln;
end.
And i have also another problem too, i saw the prime topic and i still don't get the codes, hwo would i fine the prime ?
If you guys can help me, i will be really thankful

Edited by WingedPanther, 25 December 2008 - 02:42 PM.
add code tags (the # button)


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
For 1) the LAST assignment to prime is the only one that will "stick". You should get all 1 or all 0. Perhaps you meant to use an array?

For 2), 'A' is not the same as 'a', so you are probably only incrementing u.

Final: do you mean "how do you check if a number is prime?" or "How do I find a prime?"
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
rlpp

rlpp

    Newbie

  • Members
  • Pip
  • 2 posts
For 1 )thx i will try it
For 2 ) even when i type a or A(i tried both) i will only get my last input,
for example input 2 a,b output 0,1,0,0,0,0,0 and so on, i will not get the a.
Final: how do you check if a number is a prime
thank you very much

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
For the a, b, what I would do is check trim(uppercase©) against 'A', 'B', etc.
Can you tell me whether 10 is prime? how about 17? Think about why they are or are not prime.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog