cs1713-day0-prog3.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (C) 2020, 2019, 2018, 2017 Girish M
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  16. * MA 02110-1301, USA.
  17. *
  18. */
  19. /*-----------------------------------
  20. Name: Girish M
  21. Roll number: MTech CS 13
  22. Date: 20/07/2017
  23. Program description: Find max, min and avg of list of integers
  24. Acknowledgements:
  25. ------------------------------------*/
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. int main(void)
  29. {
  30. int num, max=0, min=0, sum=0, count=0;
  31. float avg=0.0;
  32. while(1)
  33. {
  34. printf("\nEnter number (To exit enter -1)\n");
  35. scanf("%d",&num);
  36. if(num == -1)
  37. {
  38. exit(0);
  39. }
  40. if(count == 0)
  41. {
  42. //initialize max, min and avg
  43. max = num;
  44. min = num;
  45. avg = num;
  46. }
  47. else
  48. {
  49. if(num > max)
  50. {
  51. max = num;
  52. }
  53. if(num < min)
  54. {
  55. min = num;
  56. }
  57. }
  58. sum += num;
  59. count++;
  60. avg = (float) sum / (float) count;
  61. printf("\nMax: %d Min: %d Avg: %.3f\n", max, min, avg);
  62. }
  63. return 0;
  64. }