Find a number of vowels consonants digits and special characters in c C++ code Program
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
void difference(char *string,int);
void main()
{
clrscr();
int size,count;
printf("how many elements u want ?");
scanf("%d",&size);
char *string=(char *) malloc(size*sizeof(char));
puts("\n enter string:\n ");
for(count=0;count<size;count++)
scanf("%c",&string[count]);
difference(string,size);
getch();
}
void difference(char *string,int size)
{
int count,vowel=0,cons=0,digit=0,special=0;
for(count=0;count<size;count++)
if((string[count]>=65 && string[count]<=90)||(string[count]>=97 && string[count]<=122))
if(string[count]==65 || string[count]==69 || string[count]==73 || string[count]==79 || string[count]==85 || string[count]==97 || string[count]==101 || string[count]==105 || string[count]==111 || string[count]==117)
vowel++;
else
cons++;
else if(string[count]>=48 && string[count]<=57)
digit++;
else if(string[count]!=255)
special++;
printf("\n no.of vowels =%d \n no.of consonents=%d \n no. of digits=%d \n no.of special characters=%d",vowel,cons,digit,special);
}
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
void difference(char *string,int);
void main()
{
clrscr();
int size,count;
printf("how many elements u want ?");
scanf("%d",&size);
char *string=(char *) malloc(size*sizeof(char));
puts("\n enter string:\n ");
for(count=0;count<size;count++)
scanf("%c",&string[count]);
difference(string,size);
getch();
}
void difference(char *string,int size)
{
int count,vowel=0,cons=0,digit=0,special=0;
for(count=0;count<size;count++)
if((string[count]>=65 && string[count]<=90)||(string[count]>=97 && string[count]<=122))
if(string[count]==65 || string[count]==69 || string[count]==73 || string[count]==79 || string[count]==85 || string[count]==97 || string[count]==101 || string[count]==105 || string[count]==111 || string[count]==117)
vowel++;
else
cons++;
else if(string[count]>=48 && string[count]<=57)
digit++;
else if(string[count]!=255)
special++;
printf("\n no.of vowels =%d \n no.of consonents=%d \n no. of digits=%d \n no.of special characters=%d",vowel,cons,digit,special);
}
0 comments:
Post a Comment