#include
#include
void main()
{
char ch[20];
clrscr();
printf("\nEnter any string:");
scanf("%s",ch);
for(int i=0 ;i<20;i++)
{
if(ch[i] >= 97 && ch[i] <=123)
ch[i] -= 32;
}
printf("Text in upper case=%s",ch);
getch();
}
---------------------------------------------------------
22. Count Vowels:
#include
#include
void main()
{
char ch[20];
int space=0, vovel=0, cons=0;
clrscr();
printf("\nEnter any string:");
scanf("%s",ch);
for(int i=0 ; ch[i]!= '\0' ;i++)
{
if(ch[i] == ' ')
space++;
else if(ch[i] == 97 || ch[i] == 101 || ch[i] == 105 || ch[i] == 111 || ch[i] == 117)
vovel++;
else if((ch[i] >= 97 && ch[i] <=123) || (ch[i] >= 65 && ch[i] <=91))
cons++;
}
printf("\n\nSpace=%d, Vovels=%d, Consonants=%d",space,vovel,cons);
getch();
}
------------------------------------------------------------
23. Reverse String:
#include
#include
#include
int main(void)
{
clrscr();
char str1[] = "Default String";
char str2[80], *p1, *p2;
/* make p point to end of str1 */
p1 = str1 + strlen(str1) - 1;
p2 = str2;
while(p1 >= str1)
*p2++ = *p1--;
/* null terminate str2 */
*p2 = '\0';
printf("\nGiven String=%s\n\nReverse=%s", str1, str2);
getch();
return 0;
}
No comments:
Post a Comment