void Get Arrayint a int size void Print

  • Slides: 20
Download presentation

void Get. Array(int a[], int size); void Print. Array(int a[], int size); int main()

void Get. Array(int a[], int size); void Print. Array(int a[], int size); int main() { int a[SIZE]; Get. Array(a, SIZE); Print. Array(a, SIZE); return 0; }

 חשבון מצביעים reverse_array(my_arr, my_arr + SIZE -1); void reverse_array(int *begin, int *end) {

חשבון מצביעים reverse_array(my_arr, my_arr + SIZE -1); void reverse_array(int *begin, int *end) { while (begin < end) { swap(begin, end); begin++; end--; } } 31 begin 5 7 31 end

#include <stdio. h> int strlen(char *str) { char *eos; eos = str; while (

#include <stdio. h> int strlen(char *str) { char *eos; eos = str; while ( *eos != ‘’ ) eos++; return eos - str; } void main() { char str[]="LINUX"; printf("%dn", strlen(str)); } 100 101 102 103 104 105 106 L str I N U X ‘’ eos

#include <stdio. h> int compare (char s 1[ ], char s 2[ ]) {

#include <stdio. h> int compare (char s 1[ ], char s 2[ ]) { int k; for ( k=0; s 1[k] != ‘’ || s 2[k] != ‘’; k++ ) if ( s 1[k] != s 2[k] ) return 0; return 1; } void main() { char s 1[11], s 2[11]; scanf(“%10 s”, s 1, s 2); printf(“%dn”, compare(s 1, s 2)); }

#include <stdio. h> char *strstr ( char * str 1, char * str 2)

#include <stdio. h> char *strstr ( char * str 1, char * str 2) { char *cp = str 1; char *s 1, *s 2; if ( *str 2 == ‘’ ) return str 1; while ( *cp != ‘’ ) { s 1 = cp; s 2 = str 2; while ( *s 1 != ‘’ && *s 2 != ‘’ && *s 1 == *s 2 ) { s 1++; s 2++; } if ( *s 2 == ‘’ ) return cp; cp++; } return NULL; בדיקת תת המחרוזת } void main() { char s 1[]="I am a boy"; char s 2[]="am"; printf("%sn", strstr(s 1, s 2)); }

#include <stdio. h> #include <string. h> int main() { char s[101]; int k, len;

#include <stdio. h> #include <string. h> int main() { char s[101]; int k, len; scanf(“%100 s”, s); len = strlen(s); for ( k=0; k<len/2; k++ ) if ( s[k] != s[len-1 -k] ) { printf(“The string is not a palindrome!n”); return 0; } } printf(“The string is a palindrome!n”); return 0;

int word_cnt (char *s) { int cnt = 0; char *next = s +

int word_cnt (char *s) { int cnt = 0; char *next = s + 1; if (*s == '') // empty string return 0; while(*next != '') { if (!isspace(*s) && isspace(*next)) cnt++; s++; next++; } if (!isspace(*s)) cnt++; return cnt; }