Help translate this code to C:

begin ch:=random(100); write(ch, ' '); if ch mod 2 = 0 then inc(cnt) else if ((ch mod 2 <> 0) and (ch > max)) then max:=ch; end; 

Closed due to the fact that off-topic participants ߊߚߤߘ , jfs , Viktor Tomilov , 0xdb , Suvitruf 5 Feb '18 at 1:19 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • " Learning tasks are allowed as questions only on the condition that you tried to solve them yourself before asking a question . Please edit the question and indicate what caused you difficulties in solving the problem. For example, give the code you wrote, trying to solve a problem "- Viktor Tomilov, 0xdb, Suvitruf
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 2
    And what is the problem? - Nicolas Chabanovsky
  • Exactly how to write to c: ch: = random (100); And this: if ch mod 2 = 0 then inc (cnt) - Timi

1 answer 1

 ch=rand()%100+1; printf("%c ",ch); if(ch%2==0) cnt++; else if(ch>max) max=ch; 
  • 2
    And pay attention to the absence of useless verification of the condition (ch mod 2 <> 0) - Alexey Kotov