IHYPRESS PROGRAMMING
Tutorials and C programs with code and output for beginners
c programming
HOME | ASP | C | CSS | GNUPLOT | HTML | JAVASCRIPT | PERL | PHP | PYTHON | RUBY | SVG
CAdvanced Programming : Personal Libraries
<12.04>
#include <stdio.h> #include "arrays.h" #define SIZE 14 int main (void) { int a[SIZE] = {101,56,78,23,74,364,53,5,83,12,89,44,77,178}; printf ("Smallest number in array is: %d.\n", findsmall(a,SIZE)); printf ("Largest number in array is: %d.\n", findlarge(a,SIZE)); printf ("Smallest even number in array is: %d.\n", findsmalleven(a,SIZE)); printf ("Largest even number in array is: %d.\n", findlargeeven(a,SIZE)); printf ("Smallest odd number in array is: %d.\n", findsmallodd(a,SIZE)); printf ("Largest odd number in array is: %d.\n", findlargeodd(a,SIZE)); return (0); } //content of library "arrays.h" int findsmall (int arr[], int size) { int i, small; small = arr[0]; for (i = 0; i < size; ++i) if (arr[i] < small) small = arr[i]; return (small); } int findlarge (int arr[], int size) { int i, large; large = arr[0]; for (i = 0; i < size; ++i) if (arr[i] > large) large = arr[i]; return (large); } int findsmalleven (int arr[], int size) { int i, small; small = arr[0]; for (i = 0; i < size; ++i) if (arr[i] < small && arr[i]%2==0) small = arr[i]; return (small); } int findlargeeven (int arr[], int size) { int i, large; large = arr[0]; for (i = 0; i < size; ++i) if (arr[i] > large && arr[i]%2==0) large = arr[i]; return (large); } int findsmallodd (int arr[], int size) { int i, small; small = arr[0]; for (i = 0; i < size; ++i) if (arr[i] < small && arr[i]%2==1) small = arr[i]; return (small); } int findlargeodd (int arr[], int size) { int i, large; large = arr[0]; for (i = 0; i < size; ++i) if (arr[i] > large && arr[i]%2==1) large = arr[i]; return (large); }
Hergestellt in Deutschland / Made in Germany
Smallest number in array is: 5. Largest number in array is: 364. Smallest even number in array is: 12. Largest even number in array is: 364. Smallest odd number in array is: 5. Largest odd number in array is: 101.
COPYRIGHT © 2015-2024 IHY PRESS Frankfurt am Main 60329 Deutschland