# Lecture31 - What Next Derived Data types Arrays...

This preview shows pages 1–6. Sign up to view the full content.

1 Computer Programming I TA C162 . 31 Mar 2006 What Next… Derived Data types Arrays Declarations and Initialization One dimensional Arrays Two dimensional Arrays Multi dimensional Arrays Character Arrays One dimensional Two dimensional

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

View Full Document
2 Computer Programming I TA C162 . 31 Mar 2006 Arranging List of numbers in Ascending Order Algorithm Steps : 1. Read an array a[] of N elements, precondition N>=1 2. Repeat (3) for i =0 to N -1 3. Repeat (4) for j=0 to N - i 4. Swap a[j] and a[j+1] for every a[j] > a[j+1] 5. Display the ordered list.
3 Computer Programming I TA C162 . 31 Mar 2006 Implementation /* Arranging a list of integer numbers */ #include<stdio.h> #define SIZE 10 void main() { int a[SIZE],i,j,temp; printf(“Enter 10 numbers”); /* Reading the array elements */ for(i=0; i<SIZE; i++) scanf(“%d”,&a[i]);

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

View Full Document
4 Computer Programming I TA C162 . 31 Mar 2006 Cont…. for(i=0; i<SIZE-1; i++) { for(j=0; j<(SIZE-i)-1; j++) { if(a[j]>a[j+1]) { temp = a[j]; a[j] = a[j+1]; a[j+1] = temp; } } } /* Display Arranged list of numbers */ for(i=0; i<SIZE; i++) printf(“%d,”,a[i]); }
5 Computer Programming I TA C162 . 31 Mar 2006

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 16

Lecture31 - What Next Derived Data types Arrays...

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

View Full Document
Ask a homework question - tutors are online