{ char s; int i, j, m;
for (m=0; e[m]!=’\0’; m++)
for(j=0, j=m-i; i
{ s=e[i]; e[i] = e[j]; e[j] =s; } }
Dasturdagi void toifadan ma’lumki, bu funksiya hech qanday qiymat qaytarmaydi.
Masalan:
# include
int main( )
{ char ct[ ] =”0123456789”;
void invert (char [ ]);
invert(ct); cout << ct; }
Natija: 9876543210
Satrning chap tomonidan kiritilgan boshqa satrni qidirish funksiyasi:
int index(char *ct1, char *ct2)
{ int i, j, m1, m2;
for(m1=0; ct1[m1]!=’\0’; m1++)
for(m2=0; ct2[m2]!=’\0’; m2++)
if (m2>m1) return -1;
for(i=0; i
{ for(j=0; j
if (ct2[j] !=ct1[i+j] ) break;
if (j==m2) return 1; }
return -1; }
Funksiyaning ishlashiga misol:
# include
int main ( )
{ char c1[ ] =”og`irlik_yig`indisi”;
int index(char[ ], char[ ]);
char c2[ ] = “non”;
char c3[ ] = “olma”;
cout<< index(c1,c2);
cout<< index(c1,c3);
}
Do'stlaringiz bilan baham: |