Problem Description
Count vowels and constants in a given string using pointersTest Case 1
Input (stdin)welcome
Expected Output3 4
Test Case 2
Input (stdin)hello
Expected Output2 3
Program
#include <stdio.h> int main() { char str[20]; char *ptr; int cntV; int cntC; scanf("%s",str); ptr=str; cntV=cntC=0; while(*ptr!='\0') { if(*ptr=='a'||*ptr=='e'||*ptr=='i'||*ptr=='o'||*ptr=='u') cntV++; else cntC++; ptr++; } printf("%d %d\n",cntV,cntC); return 0; }
No comments:
Post a Comment
Note: only a member of this blog may post a comment.