COUNTING THE NO.OF VOWELS, CONSONANTS, WORDS AND WHITE SPACES

      /*  COUNTING THE NO.OF VOWELS, CONSONANTS, WORDS
                       AND WHITE SPACES                 */


#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
 {
   int i,len,s=0,w=1,c=0,v=0;
   char s1[20],ch;
   clrscr();
   printf("\n\t\tINPUT:");
   printf("\n\t\t------");
   printf("\n\t\tEnter the Text:  ");
   gets(s1);
   len=strlen(s1);
   for(i=0;i<=len-1;i++)
    {
     ch=s1[i];
     switch(ch)
      {
        case 'A':
        case 'E':
        case 'I':
        case 'O':
        case 'U':
        case 'a':
        case 'e':
        case 'i':
        case 'o':
        case 'u':
               v++;
               break;
        case ' ':
               s++;
               break;
        default:
               c++;
      }
     if(s1[i]==' ' && s1[i-1]!=' ')
      {
        w++;
      }
    }
   printf("\n\t\tOUTPUT:");
   printf("\n\t\t-------");
    printf("\n\t\tThe number of vowels is:  %d",v);
    printf("\n\t\tThe number of consonants is:  %d",c);
    printf("\n\t\tThe number of words is:  %d",w);
    printf("\n\t\tThe number of white spaces is:  %d",s);
    getch();
  }

 INPUT:
------
Enter the Text:  I am belongs to BCA

OUTPUT:
-------
The number of vowels is:  6
The number of consonants is:  9
The number of words is:  5
The number of white spaces is:  4


SUMMATION OF EXPONENTIAL SERIES

/*  SUMMATION OF EXPONENTIAL SERIES  */

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
  {
    int x,n,i,prod;
    float t,sum;
    clrscr();
    printf("\n\t\tINPUT:");
    printf("\n\t\t------");
    printf("\n\t\tEnter the value for x:  ");
    scanf("%d",&x);
    printf("\n\t\tEnter the value for n:  ");
    scanf("%d",&n);
    printf("\n\t\tOUTPUT:");
    printf("\n\t\t-------");
    sum=1;
    t=1;
    for(i=1;i<=n;i++)
     {
       prod=i;
       t=t*x/prod;
       sum=sum+t;
     }
    printf("\n\t\tThe value for exp %d is:  %f",x,sum);
    printf("\n\t\tThe built-in value for given value is: 
                                              %f",exp(x));
    getch();
   }

INPUT:
------
Enter the value for x:  1
Enter the value for n:  5

OUTPUT:
-------
The value for exp 1 is:  2.716667
The built-in value for given value is:  2.718282

SUMMATION OF COSINE SERIES

/*  SUMMATION OF COSINE SERIES  */

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
 {
    int x,n,t=-1,i,j;
    double num,sum=1.0,r;
    long int deno;
    clrscr();
    printf("\n\t\tINPUT:");
    printf("\n\t\t------");
    printf("\n\t\tEnter the value for x:  ");
    scanf("%d",&x);
    printf("\n\t\tEnter the value for n:  ");
    scanf("%d",&n);
    printf("\n\t\tOUTPUT:");
    printf("\n\t\t-------");
    r=x*(3.14/180.0);
    printf("\n\t\tThe radius value for the given x value
                                             is:  %lf",r);
    for(i=2;i<=n;i+=2)
     {
       num=1.0;
       deno=1;
       for(j=2;j<=i;j++)
        {
          num=num*r;
          deno=deno*j;
        }
       sum=sum+num/deno*t;
       t=t*-1;
     }
    printf("\n\t\tThe value for cos %d is:  %lf",x,sum);
    printf("\n\t\tThe built-in value for given value is: 
    %lf",cos(r));
    getch();
  }

 INPUT:
 ------
 Enter the value for x:  60
 Enter the value for n:  4

 OUTPUT:
 -------
 The radius value for the given x value is:  1.046667               
 The value for cos 60 is:  0.524443
 The built-in value for given value is:  0.500460

SUMMATION OF SINE SERIES

/ *  SUMMATION OF SINE SERIES  */

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
 {
    int x,n,t=1,i,j;
    double num,sum=0.0,r;
    long int deno;
    clrscr();
    printf("\n\t\tINPUT:");
    printf("\n\t\t------");
    printf("\n\t\tEnter the value for x:  ");
    scanf("%d",&x);
    printf("\n\t\tEnter the value for n:  ");
    scanf("%d",&n);
    printf("\n\t\tOUTPUT:");
    printf("\n\t\t-------");
    r=x*(3.14/180.0);
    printf("\n\t\tThe radius value for the given x value
                                            is:  %lf",r);
    for(i=1;i<=n;i+=2)
     {
       num=1.0;
       deno=1;
       for(j=1;j<=i;j++)
         {
           num=num*r;
           deno=deno*j;
         }
       sum=sum+num/deno*t;
       t=t*-1;
     }
    printf("\n\t\tThe value for sin %d is:  %lf",x,sum);
    printf("\n\t\tThe built-in value for given value is: 
                                             %lf",sin(r));
    getch();
  }


INPUT:
------
Enter the value for x:  30
Enter the value for n:  3

OUTPUT:
-------
The radius value for the given x value is:  0.523333
The value for sin 30 is:  0.499445
The built-in value for given value is:  0.499770



Related Posts with Thumbnails