{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lec31 - Computer Programming I TA C162 Today's Agenda...

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

View Full Document Right Arrow Icon
1 Computer Programming I TA C162 . 5 Apr 2007 Today’s Agenda Character Arrays One dimensional Arrays  Coding Examples Arrays of strings (Two Dimensional Char Arrays) Declaration Initialization Printing Reading Coding Examples
Image of page 1

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

View Full Document Right Arrow Icon
2 Computer Programming I TA C162 . 5 Apr 2007 Palindrome problem: Algorithm Design 1. Read a string in str[0….n-1]   pre condition n>=1 2.  Initialize left = 0 and right = n-1 1. Repeat for  left<right         3.1  str[left] != str[right] terminate with false         3.2  Increment left and decrement right 1. Terminate with true  Post condition   Returns false If str[left] != str[right] for any value of left>=0 and right<=n-1  Where left<right
Image of page 2
3 Computer Programming I TA C162 . 5 Apr 2007 Palindrome problem: Implementation void main() { char str[80]; int left,right,i,len,flag = 1; printf("Enter a string"); for(i = 0;(str[i] = getchar())!='\n';++i); len = i-1; for(left = 0,right = len; left < right; ++left,--right) { if(str[left]!= str[right]) { flag = 0; break; } } if(flag)printf("\n String is palindrome"); else printf("\n String is not a palindrome"); } Exercise: Write equivalent while loop for the above.
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
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