Pascal Program to Find The Average Of Only Positive Numbers Using While Do loop

Given below, is a Pascal Program to find the average of only positive numbers using the WHILE DO looping statement.

Keep in mind that a WHILE DO statement continues the execution of that statement as long as the condition is true, and terminates when the condition is false.

The WHILE DO program structure or syntax in Pascal is usually given by:

WHILE  (Condition) 




You can repeat the execution of a statement or groups of statements in a subprogram till the condition is satisfied.

Logic of The Program

This program calculates the sum and average of only three positive numbers. 

This is made possible with a looping statement called WHILE DO as stated above, and it allows the user enter another number after the first until we have our three numbers.

The decision on whether positive or negative numbers are to be calculated is determined by a conditional IF-THEN statement that either proceeds on calculating the sum and average of the number if positive, or requests for a new number if negative.

This means that any negative number entered by the user is ignored and at least the first 3 positive numbers entered will be computed.

                   Pascal Arithmetic Program Using IF THEN statement
                   Pascal Program to Create and Save Records in a Textfile
                   Pascal Program of Matrix Multiplication

Program Code

Program Positive_Numbers_Only;
Label 10;
Sum, Ave, N: real;
I : integer;
I:=0; sum:=0;
While i<=3 do
10: Writeln ('enter the numbers');
       Readln (N);
        If N < 0 then goto 10
          Sum:= sum + N;
          I:= i+1;
        Ave:= sum/3;
    Writeln ('the average',ave);


Pascal Program codes are the simplest you'll have to write if you're learning to program for the first time.

If you can understand the control statements and the way they are used to solve simple arithmetic problems, then you'll have no issues writing complex programming codes, especially in complex programming languages.

If you have questions regarding this Pascal code example, you can leave a comment below and we'll respond as soon as we can.


Tech blogger, SEO expert, cryptocurrency enthusiast, and freelancer are the terms that describe me. I'll rather write a thousand words than speak hundred words, and that describes my passion as a content creator.