C program which will count the total number of vowels and numbers in a String
Programming code :
#include <stdio.h>
int main()
{
char line[1000];
int i, vowels=0,digits=0;
printf("Enter a line of string: ");
scanf("%s", line);
for(i=0; line[i]!='\0'; ++i)
{
if(line[i]=='a' || line[i]=='e' || line[i]=='i' ||line[i]=='o' || line[i]=='u' || line[i]=='A' ||line[i]=='E' || line[i]=='I' || line[i]=='O' ||line[i]=='U')
{
++vowels;
}
if(line[i]>='0' && line[i]<='9')
{
++digits;
}
}
printf("Vowels: %d",vowels);
printf("\nDigits: %d",digits);
return 0;
}
Output :
#include <stdio.h>
int main()
{
char line[1000];
int i, vowels=0,digits=0;
printf("Enter a line of string: ");
scanf("%s", line);
for(i=0; line[i]!='\0'; ++i)
{
if(line[i]=='a' || line[i]=='e' || line[i]=='i' ||line[i]=='o' || line[i]=='u' || line[i]=='A' ||line[i]=='E' || line[i]=='I' || line[i]=='O' ||line[i]=='U')
{
++vowels;
}
if(line[i]>='0' && line[i]<='9')
{
++digits;
}
}
printf("Vowels: %d",vowels);
printf("\nDigits: %d",digits);
return 0;
}
Output :
No comments