This blog consists of C and C++ programs. C and C++ programming is the basics to learn any programming language. Most of the programs are provided with their respective outputs. This blog also contains Data Structures programs using Object-Oriented Programming (C++). Some of the best books for learning C and C++ programming are also mentioned.

Wednesday 7 August 2013

Program to find the number of vowels, consonants, digits, spaces and other characters

#include<stdio.h>
main()
{
char text[100];
int nv=0, nc=0, nd=0, ns=0, no=0;
void input(char text[], int *pv, int *pc, int *pd, int *ps, int *po);
clrscr();
printf("Enter a line of text: ");
gets(text);
input(text, &nv, &nc, &nd, &ns, &no);
printf("\nNo of Vowels:%d", nv);
printf("\nNo of Consonants:%d", nc);
printf("\nNo of Digits:%d", nd);
printf("\nNo of Spaces:%d", ns);
printf("\nNo of Other Characters:%d", no);
getch();
}
void input(char text[], int *pv, int *pc, int *pd, int *ps, int *po)
{
char c;
int i=0;
while((c=toupper(text[i]))!='\0')
{
if(c=='A'||c=='E'||c=='I'||c=='O'||c=='U')
++*pv;
else if(c>='A'&&c<='Z')
++*pc;
else if(c>='0'&&c<='9')
++*pd;
else if(c==' '||c=='\t')
++*ps;
else
++*po;
++i;
}
}


No comments:

Post a Comment