Tuesday, August 13, 2013

Write a program in c to accept a string from console and to display the following on console. a. Total no. of character in the string. b. Total no. of vowels in the string. c. Total no. of occurence of character 'a' in the string. d. Total no. of occurence of string 'the' in the string.

Program : Write a program in c to accept a string from console and to display the following on console.

      a. Total no. of character in the string.
      b. Total no. of vowels in the string.
      c. Total no. of occurence of character 'a' in the string.
      d. Total no. of occurence of string 'the' in the string.


#include<stdio.h>
#include<conio.h>


void main()
 {
  char name[15];
  int ch,i=0,cnt1=0,cnt2=0;
  clrscr();
  printf("\n\t --------MENU-----------");
  printf("\n\t1.Total no. of character in the string");
  printf("\n\t2.Total no. of vowels in the string");
  printf("\n\t3.Total no. of occurence of character 'a' in the string");
  printf("\n\t4.Total no. of occurence of string 'the' in the string");
  printf("\n\t5.Exit");
  printf("\n\t  Enter Your Choice==>");
  scanf("%d",&ch);
  switch(ch)
   {
     case 1:
      printf("Enter Any string\n");
      scanf("%s",&name);
      while(name[i]!='\0')
 {
  i++;
 }
      printf("\n\nThe length of %s=%d",name,i);
      break;
     case 2:
      printf("Enter Any string\n");
      scanf("%s",&name);
      while(name[i]!=NULL)
 {
  if(name[i]=='a'||name[i]=='e'||name[i]=='i'||name[i]=='o'||name[i]=='u')
   {
    cnt1++;
   }
   i++;
 }
      printf("Total no. of vowels present in the string=%d",cnt1);
      break;
     case 3:
      printf("Enter Any string\n");
      scanf("%s",&name);
      while(name[i]!=NULL)
 {
  if(name[i]=='a')
   {
    cnt1++;
   }
  i++;
 }
      printf("Total no. of'a'present in the string=%d",cnt1);
      break;
     case 4:
      printf("Enter Any string\n");
      scanf("%s",&name);
      while(name[i]!=NULL)
 {
  if(name[i]=='t')
   {
    i++;
    if(name[i]=='h')
     {
      i++;
      if(name[i]=='e')
       {
        cnt2++;
       }
     }
   }
  i++;
 }
      printf("Total no. of'the'present in the string=%d",cnt2);
      break;
     case 5:
      exit(0);
      break;
    default:
      printf("\n\t Invalid Choice");
      break;
  }
  getch();
 }






/**************************  OUTPUT WINDOW  ************************/



--------MENU-----------
1.Total no. of character in the string
2.Total no. of vowels in the string
3.Total no. of occurence of character 'a' in the string
4.Total no. of occurence of string 'the' in the string
5.Exit
 Enter Your Choice==>1
Enter Any string
jabir


The length of jabir=5





--------MENU-----------
1.Total no. of character in the string
2.Total no. of vowels in the string
3.Total no. of occurence of character 'a' in the string
4.Total no. of occurence of string 'the' in the string
5.Exit
 Enter Your Choice==>2
Enter Any string
jabir
Total no. of vowels present in the string=2





--------MENU-----------
1.Total no. of character in the string
2.Total no. of vowels in the string
3.Total no. of occurence of character 'a' in the string
4.Total no. of occurence of string 'the' in the string
5.Exit
 Enter Your Choice==>3
Enter Any string
jabir
Total no. of'a'present in the string=1






         --------MENU-----------
        1.Total no. of character in the string
        2.Total no. of vowels in the string
        3.Total no. of occurence of character 'a' in the string
        4.Total no. of occurence of string 'the' in the string
        5.Exit
          Enter Your Choice==>4
Enter Any string
the india
Total no. of'the'present in the string=1







       --------MENU-----------
1.Total no. of character in the string
2.Total no. of vowels in the string
3.Total no. of occurence of character 'a' in the string
4.Total no. of occurence of string 'the' in the string
5.Exit
 Enter Your Choice==>5





--------MENU-----------
1.Total no. of character in the string
2.Total no. of vowels in the string
3.Total no. of occurence of character 'a' in the string
4.Total no. of occurence of string 'the' in the string
5.Exit
 Enter Your Choice==>7

Invalid Choice

No comments:

Post a Comment