Thursday, December 10, 2009

C++-->STORE NAMES OF N STUDENTS INTO AN ARRAY

Store names of n students into an array and then search for a particular name

#include

#include

#include

#include

void main()

{

int i,n,big;

int flag;

char name[100][25];

char t[25];

cout<<”Enter how many elements : “;

cin>>n;

for(i=0;i
gets(name[i]);



cout<<”Enter a name for search : “;

gets(t);

flag=0;

for(i=0;i
if(strcmp(name[i],t==0)

{

flag=1;

break;

}

if(flag= =1)

cout<<”The given name is found in the position “<
else

cout<<”The given name is not found”;

getch();

}

Tuesday, December 8, 2009

C++->BIGGEST NUMBER

Write a program to store n numbers into an array and find the biggest number along with its position
#include

#include

void main()

{

int ar[100],i,n,big;

cout<<”Enter how many elements : “;

cin>>n;

cout<<”Enter the elements \n”;

for(i=0;i
cin>>ar[i];











big=ar[0];

for(i=1;i
if(ar[i]>big)

big=ar[i];

cout<<”Biggest number is : “<
getch();

}

Monday, December 7, 2009

C++->PRIME NUMBERS

Find the prime numbers between 1 and 100

#include

#include

#include

void main()

{

int i,j,n,p;

clrscr();

int flag;

for(i=1;i<=100;i++)

{

p=i;

flag=1;

for(j=2;j<=p/2;j++)

if((p%j)= = 0)

{

flag=0;

break;

}

if(flag= = 1)

cout<
}

getch();

}

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