diff options
Diffstat (limited to '662/CH6/EX6.31')
-rwxr-xr-x | 662/CH6/EX6.31/ex6_31.JPG | bin | 0 -> 18281 bytes | |||
-rwxr-xr-x | 662/CH6/EX6.31/ex6_31.sce | 20 |
2 files changed, 20 insertions, 0 deletions
diff --git a/662/CH6/EX6.31/ex6_31.JPG b/662/CH6/EX6.31/ex6_31.JPG Binary files differnew file mode 100755 index 000000000..ff8b56128 --- /dev/null +++ b/662/CH6/EX6.31/ex6_31.JPG diff --git a/662/CH6/EX6.31/ex6_31.sce b/662/CH6/EX6.31/ex6_31.sce new file mode 100755 index 000000000..aba9bef84 --- /dev/null +++ b/662/CH6/EX6.31/ex6_31.sce @@ -0,0 +1,20 @@ + //Programming Example 6.31
+//Averaging a list of nonnegative numbers
+navg=0;
+Sum=0;
+//initialize and read in a value for n
+printf("How many numbers ? ");
+n=scanf("%d");
+//read in the numbers
+for count = 1:1:n
+ printf("x= ");
+ x=scanf("%f");
+ if x<0 then
+ continue;
+ end
+ Sum=Sum+x;
+ navg=navg+1;
+end
+//calculate the average and write out the answer
+average=Sum/navg;
+printf("\n The average is %f\n", average);
|