Using the while do loop, the program calculates the sum and average of only three positive numbers. Any negative number entered by the user is ignored.
Program Positve;
Label 10;
Var
Sum, Ave, N: real;
I : integer;
Begin
I:=0; sum:=0;
While i<=3 do
Begin
10: Writeln ('enter the numbers');
Readln (N);
If N < 0 then goto 10
Else
Sum:= sum + N;
I:= i+1;
End;
Ave:= sum/3;
Writeln ('the average',ave);
Readln;
End.
Using the while do loop, the program calculates the sum and average of only three positive numbers. Any negative number entered by the user is ignored.
Program Positve;
Label 10;
Var
Sum, Ave, N: real;
I : integer;
Begin
I:=0; sum:=0;
While i<=3 do
Begin
10: Writeln ('enter the numbers');
Readln (N);
If N < 0 then goto 10
Else
Sum:= sum + N;
I:= i+1;
End;
Ave:= sum/3;
Writeln ('the average',ave);
Readln;
End.
No Comment