{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

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

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

View Full Document
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
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.

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 ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern