Tuesday, November 19, 2013

STRING


Que:- WAP TO INPUT ANY STRING AND COUNT NO. OF VOWELS.

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

 void main()
 {
char str[20];
int i;
int vc=0;

clrscr();

printf("\n Enter any string -->  ");
scanf("%s",str);

i=0;
while(str[i]!='\0')
{
if(str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u'||str[i]=='A'||str[i]=='E'||str[i]=='I'||str[i]=='O'||str[i]=='U')
vc++;
i++;
}
printf("\n No. of vowels in %s= %d",str,vc);
getch();
 }

Wednesday, November 13, 2013

FOLLOWING FORMAT

/* WAP TO PRINT THE FOLLOWING FORMAT  :-
   *
 *   *
*   *   *
     *   *   *   *
   *   *   *   *   *           



#include<stdio.h>
#include<conio.h>
 void main()
 {
int i,j;
int row,space;

clrscr();

printf("Enter the no. of rows you want= ");
scanf("%d",&row);
clrscr();
space=row-1;
for(i=1;i<=row;i++)
{
for(j=1;j<=space;j++)
{
printf("  ");                     // 2-SPACES.
}
for(j=1;j<=i;j++)
{
printf("*   ");                   // 1 * & 3-SPACES.
}
printf("\n");
space=space-1;
}
getch();
 }

FOLLOWING FORMAT

/* WAP TO PRINT THE FOLLOWING FORMAT  :-
   *
 *   *
*   *   *
     *   *   *   *
   *   *   *   *   *           



#include<stdio.h>
#include<conio.h>
 void main()
 {
int i,j;
int row,space;

clrscr();

printf("Enter the no. of rows you want= ");
scanf("%d",&row);
clrscr();
space=row-1;
for(i=1;i<=row;i++)
{
for(j=1;j<=space;j++)
{
printf("  ");                     // 2-SPACES.
}
for(j=1;j<=i;j++)
{
printf("*   ");                   // 1 * & 3-SPACES.
}
printf("\n");
space=space-1;
}
getch();
 }

/*WAP TO PRINT THE FOLLOWING FORMAT:
      *
      # #
      * * *
      # # # #
      * * * * *      


#include<stdio.h>
#include<conio.h>
 void main()
 {
int i;
int j;

clrscr();

for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
if(i%2!=0)
printf(" *");
else
printf(" #");
}
printf("\n");
}
getch();
 }












#include<stdio.h>
#include<conio.h>
 void main()
 {
int i,j;
int row,space;

clrscr();

printf("Enter the no. of rows you want= ");
scanf("%d",&row);
clrscr();
space=row-1;
for(i=1;i<=row;i++)
{
for(j=1;j<=space;j++)
{
printf("  ");
}
for(j=1;j<=i;j++)
{
printf("* ");
}
printf("\n");
space=space-1;
}
getch();
 }

Tuesday, November 5, 2013

SUM OF THE SREIES

/*THE NATURAL LOGARITHM CAN BE APPROXIMATED BY THE FOLLOWING SERIES: (x-1/x)+[1/2(x-1/x)*(x-1/x)]+[1/2(x-1/x)*(x-1/x)*(x-1/x)].....upto 7 terms.  IF x IS INPUT THROUGH THE KEYBOARD, WAP OT CALCULATE SUM OF THE SREIES*/



#include<stdio.h>
#include<conio.h>
#include<math.h>
 void main()
 {
int x;
int i;
float sum=0;

clrscr();

printf("\nEnter the value of x= ");
scanf("%d",&x);

if(x!=0)
{
for(i=1;i<=7;i++)
{
if(i==1)
sum=sum+pow(((x-1.0)/x),i);

else
sum=sum+(1.0/2)*pow(((x-1.0)/x),i);
}
printf("\nSum of the given series= %f",sum);
}

else
printf("\n\tERROR.\n\tYou have entered a wrong input.");
getch();
 }