Lec29 - Computer Programming I TA C162 What Next Derived...

Info icon This preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Computer Programming I TA C162 . 29 Mar 2007 What Next… Derived Data types Arrays Declarations and Initialization One dimensional Arrays  Two dimensional Arrays Multi dimensional Arrays Character Arrays One dimensional  Two dimensional
Image of page 1

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

View Full Document Right Arrow Icon
2 Computer Programming I TA C162 . 29 Mar 2007 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 -1                       4. Swap a[j] and a[j+1] for every a[j] > a[j+1] 5. Display the ordered list.  
Image of page 2
3 Computer Programming I TA C162 . 29 Mar 2007 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]);
Image of page 3

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

View Full Document Right Arrow Icon
4 Computer Programming I TA C162 . 29 Mar 2007 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]); }
Image of page 4
5 Computer Programming I TA C162 . 29 Mar 2007 Better implementation sorted = 0; for(i=0; i<SIZE-1 && !sorted ; i++) { sorted = 1; for(j=0; j<((SIZE-i)-1); j++) { if(a[j]>a[j+1]) { sorted = 0; temp = a[j]; a[j] = a[j+1]; a[j+1] = temp; } } }
Image of page 5

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

View Full Document Right Arrow Icon
6 Computer Programming I TA C162 .
Image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern