CProgPart1 - int array1size/prints each step in...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
C Language Programming Part 1 /******************* Homework Assignment 1 Part 1` By: /******************/ #include <stdio.h> #define size 10 void disparray( int array1[], int array1size); //function declarations void sort( int array1[], int array1size); void swap( int array1[], int i, int j); int main() { int array1[size] = {4,10,5,1,6,7,3,9,8,2}; int array1size = size; printf("The original unsorted array:\n\n "); disparray(array1, array1size); printf("\n\n\n"); sort(array1, array1size); printf("The sorted array:\n\n"); disparray(array1, array1size); printf("\n\n"); system ("PAUSE"); //to pause screen return 0; } void disparray( int array1[],
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int array1size) //prints each step in array { //sorting to the screen. int x; for (x = 0; x < array1size; x++) { printf("["); printf("%d", array1[x]); printf("]"); } } void sort( int array1, int array1size) { int i, j; for (i = 1; (i <= array1size ) ; i++) { disparray(array1, array1size); printf("\n\n"); for (j = 0; j < array1size; j++) { swap(array1, i, j); } } } void swap( int array1, int i, int j) //swaps array contents. { int temp; if (array1[j] > array1[j+1]) { temp = array1[j + 1]; array1[j + 1] = array1[j]; array1[j] = temp; } }...
View Full Document

This note was uploaded on 03/30/2008 for the course CS 212 taught by Professor Dr.frey during the Spring '06 term at New Haven.

Page1 / 2

CProgPart1 - int array1size/prints each step in...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online