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();

}

Followers