123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- /*
- * Copyright (C) 2020, 2019, 2018, 2017 Girish M
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- */
- /*-----------------------------------
- Name: Girish M
- Roll number: MTech CS 13
- Date: 20/07/2017
- Program description: Find max, min and avg of list of integers
- Acknowledgements:
- ------------------------------------*/
- #include <stdio.h>
- #include <stdlib.h>
- int main(void)
- {
- int num, max=0, min=0, sum=0, count=0;
- float avg=0.0;
- while(1)
- {
- printf("\nEnter number (To exit enter -1)\n");
- scanf("%d",&num);
- if(num == -1)
- {
- exit(0);
- }
- if(count == 0)
- {
- //initialize max, min and avg
- max = num;
- min = num;
- avg = num;
- }
- else
- {
- if(num > max)
- {
- max = num;
- }
- if(num < min)
- {
- min = num;
- }
- }
- sum += num;
- count++;
- avg = (float) sum / (float) count;
- printf("\nMax: %d Min: %d Avg: %.3f\n", max, min, avg);
- }
- return 0;
- }
|