Array Parameter Sort

Array Parameter Sort - for(i=0;i<n-1;i++)...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//This program sorts an array using parameter passing #include <stdio.h> #define SIZE 5 //prototype: void load(int [],int) same without variables void load(int c3p0[],int n) //n=size of array, can also do int *c3p0 { for(int i=0;i<n;i++) { printf("Enter a # "); scanf("%d",&c3p0[i]); } } void print(int a[],int n) { for(int i=0;i<n;i++) printf("%d ",a[i]); printf("\n\n"); } void sort(int a[],int n) { int i,j,t;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: for(i=0;i&lt;n-1;i++) for(j=0;j&lt;n-1;j++) if(a[j]&gt;a[j+1]) //ascending order // if(a[j]&lt;a[j+1]) //descending order { t=a[j]; a[j]=a[j+1]; a[j+1]=t; } } void main() { int a[SIZE]; load(a,SIZE); print(a,SIZE); sort(a,SIZE); print(a,SIZE); } /* Enter a # 1 Enter a # 983 Enter a # 5 Enter a # 46 Enter a # 2461 1 983 5 46 2461 1 5 46 983 2461 Press any key to continue . . . */...
View Full Document

This note was uploaded on 10/05/2011 for the course CS 36 taught by Professor Sethhochwald during the Spring '09 term at Irvine Valley College.

Ask a homework question - tutors are online