Search This Blog

Tuesday, March 29

code to find prime no's

void main()
{



int n,i,rem=0;

cout<<"Enter the number U want to check"; cin>>n;

if(n==0)
cout<<"The number is not prime";

if(n==1)
cout<<" The number is prime";

if(n==2)
cout<<"The number is even-prime;

else
if((n!=0) && (n!=1) && (n!=2))
{
for(i=2; i {
rem=n%i;

if(rem==0)
{
break;//come out of for loop
}

}
}

if(rem==0)
{
Cout<<"The number is not a prime";
}
else
if(rem!=0)
{
cout<<"The num is a prime";
}
getch();
}

hi srilekha...neekosame ee code

void main()
{

int a[3][3];

int i,j,n;

int max=0, second_max=0;

cout<<"Enter the numbers in the array sequentially"; for(i=0;i<3;i++) { for(j=0;j<3;j++) { cin>>n;
a[i][j]=n;
}
}

// With this all the required numbers have been inserted into the array successfully as per the user's choice.This is a 3X3 array...You can change the size as per ur choice.


for(i=0;i<3;i++) { for(j=0;j<3;j++) { (if(a[i][j]>a[i][j+1])&&(a[i][j]>max))

{
max=a[i][j];
//This max has the highest element.
}
}
}


//But we have to find the second largest element...so compare all the elements again with themselves and with the max


for(i=0;i<3;i++) { for(j=0;j<3;j++) { (if(a[i][j]>a[i][j+1])&&(a[i][j]
{
second_max=a[i][j];
//This max has the highest element.
}
}
}

//Now, we have the second largest element print it out.
Cout<<"The second largest element is< getch();

}