Wednesday 6 September 2017

C-Program to know whether the character is vowel or not



#include<stdio.h>

int main()
{
  char c;
  printf("Enter a character to know whether it is vowel or not\n");
  scanf("%c",&c);
  if(c=='A'||c=='a'||c=='e'||c=='E'||c=='I'||c=='i'||c=='O'||c=='o'||c=='U'||c=='u')
    printf("The character %c is vowel\n",c);
  else
    printf("The character %c is not vowel\n",c);
return 0;
}

C-Program to Count number of vowels in a string



#include<stdio.h>

int main()
{
 char s[100];
 int i,count=0;
 printf("Enter a string to know how many vowels are there \n");
 scanf("%s",&s);
 for(i=0;s[i]!='\0';i++)
 {
   if(s[i]=='A'||s[i]=='a'||s[i]=='e'||s[i]=='E'||s[i]=='I'||s[i]=='i'||s[i]=='O'||s[i]=='o'||s[i]=='U'||s[i]=='u')
   {
     count++;
   }
 }
 if(count==0)
 {
    printf("No vowels are there \n");
 }
 else
 {
    printf("Number of vowels in %s is %d\n",s,count);
 }
return 0;
}

 

C-Program to count number of words in a sentence



#include<stdio.h>
#include<string.h>

int main()
{
    int i,word=1;
    char str[100];
    printf("Enter a string\n");
    gets(str);
    for(i=0;i<strlen(str);i++)
    {
        if(str[i]==' ')
        {
            word++;
        }
    }
    printf("%d\n",word);
  return 0;
}