Sunday, December 6, 2009

C++->SERIES FOR n ROWS

Write a program to print the following series for n rows.

a
a b
a b c
a b c d
. . . nth row. . .

#include
#include
void main()
{
int i,j,l,n;
char ch;
clrscr();
cout<<”Enter how many lines : “;
cin>>n;
l=40;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
cout<<” “;
for(j=1,ch=’a’;j<=I;j++,ch++)
cout<<” “< l=l-1;
}
getch();
}

Saturday, December 5, 2009

C++->SUM DIFFERENCE PRODUCT AND QUOTIENT

Write a program to find the sum, difference, product and quotient of two numbers using C++

#include
#include
#include
void main()
{
char ch;
float a,b,r;
clrscr();
cout<<”\n1. Sum”; cout<<”\n2. Difference”; cout<<”\n3. Product”; cout<<”\n4. Quotient”; cout<<”\n\nEnter your choice……”; ch=getchar(); switch(ch) { case ‘1’: cout<<”Enter two numbers : “; cin>>a>>b;
r=a+b;
cout<<”Sum : “<>a>>b;
r=a-b;
cout<<”Difference : “<>a>>b;
r=a*b;
cout<<”Product : “<>a>>b;
r=a/b;
cout<<”Quotient : “< break;
default:
cout<<”Invalid choice “;
}
getch();
}

Friday, December 4, 2009

C++->Capital letter, Small letter, a Digit or a Special character.

Input a character and check whether it is a Capital letter, Small letter, a Digit or a Special character.
#include
void main()
{
char ch;
ch=getchar();
if(ch >= ’A’ && ch <= ’Z’)
cout<<”Capital letter”;
else
if(ch >= ’a’ && ch <= ’z’)
cout<<”Small letter”;

else
if(ch >= ’0’ && ch <= ’9’)
cout<<”Digit”;
else
cout<<”Special character ”;
}

Followers