Click here to Skip to main content
14,971,215 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
I have the answer to this equation in Pascal. Can anyone help me convert this to c or c ++?
equation: y1+y2+y3+y4=12 yi ≥ 0 , 0 ≤ i ≤ 4

pascal code (but i cant run it) :
program selections3 (input,output);
var
x1,x2,x3: integer;
begin
for x1 :=0 to 12 do
for x2 :=0 to 12 - x1 do
for x3 :=0 to 12 - x1 - x2 do
writlen('x1=',x1-2:0,'x2='x2-2:0,'x3='x3-2:0,'x4=',12-x1-x2-x3-2:0)
end.

What I have tried:

i tride debuging it but i cant
Posted
Updated 28-Apr-21 9:54am
Comments
Jerry Jeremiah 4-May-21 1:47am
   
You can compile and run the pascal version like this: https://onlinegdb.com/BkDnkDCDu
The C++ version is: https://onlinegdb.com/HJoukD0D_

1 solution

This is not a code conversion service but I will give you a hint. The Pascal for loop of this form :
Pascal
for x1 :=0 to 12 do
looks like this in c++ :
C++
for( x1 = 0; x1 <= 12; ++x1 )
{
}
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900