# sol4 - 4#include 1 This program gets a sequence...

This preview shows pages 1–3. Sign up to view the full content.

'סמ ליגרת-תונכת סרוק 4 ןורתפל אמגוד 1 תוקיטסיטטס בושיח . #include <stdio.h> /* This program gets a sequence of non-negative input numbers, until a negative number is encountered. Then it stops and calculates the following statistics: - the minimum - the maximum - the sum - the average */ int main() { double num, max = -1, min = -1, // min/max initialized as invalid values sum = 0, avg; int count = 0; // get first input printf( "Please enter number: " ); scanf( "%lf" ,&num); if (num > 0) { min = num; max = num; } else { printf( "No numbers to calculate statistics on\n" ); return 0; } while (num > 0) { count++; sum+=num; // update minimum and maximum if (min > num) min=num; if (max < num) max=num; // get next number printf( "Please enter number: " ); scanf( "%lf" ,&num); } avg = sum/count; printf( "max=%f, min=%f, sum=%f, avg=%f\n" ,max,min,sum,avg); return 0; }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 . תויתוא שלושמ #include <stdio.h> /* This program receives as input the number of rows. It prints a letter pyramid with the specified number
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 3

sol4 - 4#include 1 This program gets a sequence...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online