C Program to Print Smallest and Largest Integers of an Array



In this program we will take an array as input from user and print the smallest and largest integers from that array.



  1. //C program to print smallest and largest integers of an array
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. void maxmin(int arr[], int n, int i)
  5. {
  6. int max=arr[0];
  7. int min=arr[0];
  8. for(i=0; i<n; i++)
  9. {
  10. if(arr[i]>max)
  11. {
  12. max=arr[i];
  13. }
  14. else if(arr[i]<min)
  15. {
  16. min=arr[i];
  17. }
  18. }
  19. printf("Largest elt is %d", max);
  20. printf("\nSmallest elt is %d", min);
  21. }
  22. int main()
  23. {
  24. int arr[10], i, n;
  25. printf("enter limit: ");
  26. scanf("%d", &n);
  27. printf("enter elts: ");
  28. for(i=0; i<n; i++)
  29. {
  30. scanf("%d", &arr[i]);
  31. }
  32. maxmin(arr, i, n);
  33. return 0;
  34. }

Output
Output!
download android app

Popular C Examples









codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube