{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# Lecture34 - Todays Agenda Character Arrays One dimensional...

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

1 Computer Programming I TA C162 . 7 Apr 2006 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 . 7 Apr 2006 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 . 7 Apr 2006 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 ]}