#include #include void swapLargestSmallest(int a[], int b[], int n); int main() { int a[20], b[20], n, i; clrscr(); printf("Enter the number of terms: "); scanf("%d", &n); printf("\nEnter the terms:\n"); for (i = 0; i < n; i++) { scanf("%d", &a[i]); b[i] = a[i]; // Copy to b[] } // Call the function BEFORE printing swapLargestSmallest(a, b, n); printf("\nThe Array entered by user is:\n"); for (i = 0; i < n; i++) { printf("%d\t", b[i]); } printf("\nThe Array after interchanging the largest and smallest element:\n"); for (i = 0; i < n; i++) { printf("%d\t", a[i]); } getch(); return 0; } void swapLargestSmallest(int a[], int b[], int n) { int sml = a[0], lar = a[0]; int spos = 0, lpos = 0, temp, i; for (i = 0; i < n; i++) { if (a[i] <= sml) { sml = a[i]; spos = i; } if (a[i] >= lar) { lar = a[i]; lpos = i; } } // Swap smallest and largest temp = a[spos]; a[spos] = a[lpos]; a[lpos] = temp; }

视频信息