Question:
W A C Program That Prints All The vowels Given In String Without Using IF and Break Statements In program?
Solution:
//Credits Gaurav and Swathi H I
#include<stdio.h>
#include<stdlib.h>
main(){
char str[10];
scanf("%s",str);
int i=0;
while(str[i]!='\0'){
(str[i]=='a'|str[i]=='e'|str[i]=='i'|str[i]=='o'|str[i]=='u')? printf("%c",str[i]):printf("");
i++;
}
}
Alternative Solution:
//JavaAbhigyan
#include<stdio.h>
#include<stdlib.h>
main()
{
char str[10],c;
scanf("%s",str);
int i=0;
while((c=str[i])!='\0')
{
switch(c)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
printf("%c",c);
}
i++;
}
}
0 comments:
Post a Comment