To display and count vowel as well as consonant of a string
Topics Covered:
- Use of strlen()function
- To display vowels number from a string
- To display and count vowel as well as consonant of a string
- To sort name of n numbers of students in ascending order
//use of strlen()function
#include<conio.h>
#include<stdio.h>
int main()
{
char s[50];
printf(“enter a string”);
scanf(“%s”,&s);
printf(“the length of string=%d”,strlen(s));
return 0;
}
//to display vowels number from a string
#include<conio.h>
#include<stdio.h>
#include<string.h>
int main()
{
char s[50];
int i,l;
printf(“enter a string”);
scanf(“%s”,&s);
strlwr(s);
l=strlen(s);
for(i=0;i<=l-1;i++)
{
if(s[i]==’a’||s[i]==’e’||s[i]==’i’||s[i]==’o’||s[i]==’u’)
{
printf(“%c\n”,s[i]);
}
}
return 0;
}
/*to display and count vowel as well as consonant of a string*/
#include<conio.h>
#include<stdio.h>
#include<string.h>
int main()
{
char s[50];
int l,i,count=0,f=0;
printf(“enter a string”);
scanf(“%s”,&s);
l=strlen(s);
for(i=0;i<=l-1;i++)
{
if(s[i]==’a’||s[i]==’e’||s[i]==’i’||s[i]==’o’||s[i]==’u’)
{
count ++;
}
else
{
f++;
}
}
printf(“required vowels number=%d\n”,count);
printf(“required consonent number=%d”,f);
return 0;
}
//to sort name of n numbers of students in ascending order
#include<conio.h>
#include<stdio.h>
#include<string.h>
int main()
{
int i,j,n;
char name[100][30],temp[30];
//input section
printf(“enter number of students”);
scanf(“%d”,&n);
for(i=0;i<=n-1;i++)
{
printf(“enter name”);
scanf(“%s”,&name[i]);
}
//processing section
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(strcmp(name[i],name[j])>0)
{
strcpy(temp,name[i]);
strcpy(name[i],name[j]);
strcpy(name[j],temp);
}
}
}
//output section
printf(“name after sorting\n”);
for(i=0;i<=n-1;i++)
{
printf(“%s\n”,name[i]);
}
return 0;
}