summaryrefslogtreecommitdiff
path: root/659/CH6/EX6.5/exm6_5.sce
blob: 34071374e121d87fd9dcd0e9a4d8a071f76b85a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//               Example 6.5
//Program illustrate use of the break statement

disp("This program computes the avarage of set of numbers");
disp("Enter values and enter a NEGATIVE value at the end");
sum1=0;
for m=1:1000
    x=scanf("%f");    //Read data
    if(x<0) then
        break;       //EXIT FROM LOOP
    end
    sum1=sum1+x;     //Computes sum
end
average=sum1/(m-1);  //Computes Average
//Print the results
printf("Number of values =%d\n",m-1);
printf("sum1=%f\n",sum1);
printf("Avarage =%f\n",average);