5В011100-«Информатика» мамандығына арналған «Есеп шығару әдістемесі»



бет22/37
Дата04.04.2023
өлшемі1,37 Mb.
#79347
1   ...   18   19   20   21   22   23   24   25   ...   37
2.2 Жолдардың тіркесуіне мысалдар
5-ші листинг
/* Strcat ( ) функциясының қолданылуы*/
#include
#include
char str1[27]=”a”;char str2[2];
int main(void)
{int n; /* str2 [] жолының соңына нөлдік символдың орналасуы*/
str2[1]=’\0’;
for (n=98; n<123; n++)
{ str2[0]=n; strcat (str1,str2);
puts(str1);}
return 0;}
6-листинг
/* Strncat( ) функциясының қолданылуы*/
#include
#include
char str2[ ] = “abcdefghijklmnopqrstuvwxyz”;
int main(void)
{ char str1[27];int n;
for (n=1; n<27; n++)
{ strcpy(str1,**); strncat(str1,str2,n); puts(str1); }
return 0;}
7-ші листинг
/*strcmp ( ) функциясының қолданылуы*/
#inciude
#include
int main(void)
{ char str1[80],str2[80]; int x;
while(1)
{ /*екі жолдың кірісі.*/
printf(“\n\nInput the first string, a blank to exit:”);
gets(str1);
if (strlen(str1)= = 0) break;
printf(“\nInput the second string:”);
gets(str2);
/*салыстыру және нәтиже.*/
x=strcmp(str1,str2);
printf(“\nstrcmp(%s,%s) returns %d”, str1, str2, x); }
return 0; }
2.3 Жолдарды салыстырудың есепте қолданылуы
8-ші листинг
/* Srtncmp ( ) функциясының қолданылуы*/
#include
#include
char str1[ ] = “The first string.”; char str2[ ]= “The second string.”; int main(void)
{ size_ t n,x;
puts(str1); puts(str2);
while (1)
{ puts(“\n\nEnter number of characters to compare, 0 to exit.”); scanf(“%d”,&n);
if (n<=0) break;
x=strncmp (str1,str2,n);
printf(“\nComparing %d characters, strncmp( ) returns %d.”,n,x);}
return 0;}
2.4 Жолдар бойынша іздеуге түрлі мысалдар
9-шы листинг
/*strchr ( ) функциясының қолданылуы*/
#include
#include
int main(void)
{char*loc, buf[80];
int ch;
/*жолдың және символдың енгізілуі.*/
printf(“Enter the string to be searched:”); gets(buf);
printf(“Enter the character to search for:”);ch=getchar( );
/*іздеу.*/
loc=strchr(buf,ch);
if (loc = = NULL)
printf(“The character %c was not found.”,ch);
else printf(“The character %c was found at position %d.\n”, ch, loc-buf);
return 0;}


Достарыңызбен бөлісу:
1   ...   18   19   20   21   22   23   24   25   ...   37




©emirsaba.org 2024
әкімшілігінің қараңыз

    Басты бет