You are on page 1of 4

//write a program that would sort a list of name in alphabetical order

{
char name[30];
int i,j,l;
char n;
printf("enter your name:\n ");
gets(name);
l=strlen(name);
for(i=0;i<l-1;i++)
{for(j=i+1;j<1;j++)
{if(name[i]>name[j])
{n=name[i];
name[i]=name[j];
name[j]=n;
}
}
}
printf("\n Name in alphabetical order:\n %s", name);
return 0;
}

//a program that allow user to enter text(include space, characters,...). The program will
be terminated if user press ENTER key. Display number of words that entered form user.
{char a[1000];
int i, count=0;
printf("enter text:\n");
gets(a);
for(i=0;a[i]!='\0';i++)
{if(a[i]=' ' ||a[i]='\n'||a[i]='\t')
count++;
}
printf("\nNumber of words: %d", count+1);
return 0;}

//a program to change all the characters prompted from users to UPPER CASE
{ char a[100];
printf("enter text:\n");
gets(a);
strupr(a);
printf("\nThe text to upper case:%s",a);
return 0;}

//a program to allow user to prompt their name; then display the name in Pascal case.
{
char name[100];
printf("enter your name: ");
fgets(name, sizeof(name),stdin);
printf("\nPascalcase Name: ");
int i=0;
while(name[i]!='0'){
//check for the first character of each word
if(i==0||name[i-1]==' '){
printf("%c", toupper(name[i]));
}
else {printf("%c", tolower(name[i]));
}
i++;
}
return 0;}

//homework
char inputString[80];
char searchText[80];
char searchChar;
int Count = 0;

// Enter a string from the keyboard


printf("Enter a string (<80 characters): ");
gets(inputString);

// Enter text to search in the string


printf("Enter text to search in the above string: ");
scanf("%s", searchText);

// Enter a character to count in the string


printf("Enter a character to count in the string: ");
scanf(" %c", &searchChar);

// Count the number of times the character appears in the string


for (int i = 0; i < strlen(inputString); i++) {
if (inputString[i] == searchChar) {
Count++;
}
}
printf("The character '%c' appears %d times in the string.\n", searchChar, charCount);

// Reverse the order of characters in the string


printf("Reversed string: ");
for (int i =

return 0;
}

You might also like