You are on page 1of 3

//Vũ Ngọc Minh

Bài 2
#include <stdio.h>
#include <stdlib.h>

int main()
{
char s[500];
int vowel=0, consonant=0;
printf("Please enter a sentence: ");
scanf("%[^\n]", &s);
for (int i=0; i<strlen(s);++i)
{
if('a'==s[i]||s[i]== 'e'||s[i]=='i'||s[i]=='o'||s[i]=='u'||s[i]=='y'|| s[i]
== 'A' || s[i] == 'O' || s[i] == 'E' || s[i] == 'U' || s[i] == 'I' || s[i] ==
'Y' )
vowel++;
if(s[i] != 'a' && s[i] != 'o' && s[i] != 'e' && s[i] != 'u' && s[i] != 'i'
&& s[i] != 'y'
&& s[i] != 'A' && s[i] != 'O' && s[i] != 'E' && s[i] != 'U' &&
s[i] != 'I' && s[i] != 'Y'
&& !isdigit(s[i]) && !isspace(s[i]) && !ispunct(s[i]))
consonant++;
}
printf("The number of vowel alphabets is: %d\n", vowel);
printf("The number of consonant alphabets is: %d\n", consonant);
return 0;
}

Bài 4
#include <stdio.h>
#include <stdlib.h>

int main()
{
char s[500];
int vowel=0, consonant=0;
printf("Please enter a sentence: ");
scanf("%[^\n]", &s);
for (int i=0; i<strlen(s);++i)
{
if('a'==s[i]||s[i]== 'e'||s[i]=='i'||s[i]=='o'||s[i]=='u'||s[i]=='y'|| s[i]
== 'A' || s[i] == 'O' || s[i] == 'E' || s[i] == 'U' || s[i] == 'I' || s[i] ==
'Y' )
vowel++;
if(s[i] != 'a' && s[i] != 'o' && s[i] != 'e' && s[i] != 'u' && s[i] != 'i'
&& s[i] != 'y'
&& s[i] != 'A' && s[i] != 'O' && s[i] != 'E' && s[i] != 'U' &&
s[i] != 'I' && s[i] != 'Y'
&& !isdigit(s[i]) && !isspace(s[i]) && !ispunct(s[i]))
consonant++;
}
printf("The number of vowel alphabets is: %d\n", vowel);
printf("The number of consonant alphabets is: %d\n", consonant);
return 0;
}
Bài 5
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
char s[100];
int word=0,i;
printf("Please enter a sentence: ");
scanf("%[^\n]",s);
for (i=0;i<strlen(s);++i)
{
if (i==0)
{if ((s[i]>='a' && s[i]<='z')||(s[i]>='A'&&s[i]<='Z')) ++word;}
else if (s[i-1]==' '&&((s[i]>='a' && s[i]<='z')||(s[i]>='A'&&s[i]<='Z'))) +
+word;
}
printf("There are %d words in the sentence",word);
return 0;
}

Bài 17
#include <stdio.h>
#include <string.h>

int main()
{
char a[100], firstname[100], middlename[100], lastname[100];
int counter =1;
int n, i, j, k, flag, tmp;
printf("Please enter your full name: ");
scanf("%[^\n]",a);
n = strlen(a);
tmp =n;
for (i=0; i<tmp; i++)
{
if (a[i]==' ')
counter++;
}
if (counter==1)
{
printf("Invalid full name");
}
else
{
i=0;
while (a[i]!=' ')
{
firstname[i]=a[i];
i++;
}
firstname[i]='\0';
k=i;
i=tmp-1;
j=0;
while (a[i]!=' ')
{
lastname[j]=a[i];
i--;
j++;
}
lastname[j]='\0';
int l = 0;
for (j=k+1; j<i; j++)
{
middlename[l]=a[j];
l++;
}
middlename[l]='\0';

if (counter==2)
{
printf("The first name %s\n", firstname);
printf("The last name %s",strrev(lastname));
}
else
{
printf("First name %s\n", firstname);
printf("Middle name is %s\n",middlename);
printf("Last name is %s",strrev(lastname));
}
}

return 0;
}

You might also like