C ONLY Print every other character in the string The quick b
C ONLY
Print every other character in the string “The quick brown fox jumps over the lazy old dog”
Print only the vowels in the string “The quick brown fox jumps over the lazy old dog”
Count the number of spaces in the string “The quick brown fox jumps over the lazy old dog”
Solution
[1] Print every other character in the string “The quick brown fox jumps over the lazy old dog”
Solution :
#include <stdio.h>
#include <conio.h>
int main()
{
char str[] = \"The quick brown fox jumps over the lazy old dog\";
char flag = \'N\' ;
char cmp;
int i,j;
clrscr();
for( j = 65 ; j < 91 ; j++)
{
cmp =char(j);
flag = \'N\';
for( i = 0 ; i < str[i] !=\'\\0\' ; ++i)
{
if(str[i] != cmp)
{
}
else
{
flag = \'Y\';
break;
}
}
if(flag == \'N\')
{
printf(\" %c \",cmp);
}
}
for( j = 97 ; j < 123 ; j++)
{
cmp =char(j);
flag = \'N\';
for( i = 0 ; i < str[i] !=\'\\0\' ; ++i)
{
if(str[i] != cmp)
{
}
else
{
flag = \'Y\';
break;
}
}
if(flag == \'N\')
{
printf(\" %c \",cmp);
}
}
getch();
return 0;
}
[2] Print only the vowels in the string “The quick brown fox jumps over the lazy old dog”
#include <stdio.h>
#include <conio.h>
#include <string.h>
int main()
{
char str[] = \"The quick brown fox jumps over the lazy old dog\";
int i,length;
clrscr();
length = strlen(str);
for( i = 0 ; i < length ; i++)
{
if(str[i] == \'a\' ||
str[i] == \'e\' ||
str[i] == \'i\' ||
str[i] == \'o\' ||
str[i] == \'u\' ||
str[i] == \'A\' ||
str[i] == \'E\' ||
str[i] == \'I\' ||
str[i] == \'O\' ||
str[i] == \'U\'
)
{
printf(\"%c\",str[i]);
}
}
getch();
return 0;
}
[3] Count the number of spaces in the string “The quick brown fox jumps over the lazy old dog”
#include <stdio.h>
#include <conio.h>
int main()
{
char *str,s[1000] = \"The quick brown fox jumps over the lazy old dog\";
int i,j, space;
clrscr();
str=s;
for(space = 0;*str;str++)
{
if(*str!= \' \')
continue;
space++;
}
printf(\"%d spaces\ \",space);
getch();
return 0;
}


