srikanth gowda k


{ City } bangalore
< Country > india
* Profession * student
User No # 111013
Total Questions Posted # 0
Total Answers Posted # 2

Total Answers Posted for My Questions # 0
Total Views for My Questions # 0

Users Marked my Answers as Correct # 1
Users Marked my Answers as Wrong # 0
Questions / { srikanth gowda k }
Questions Answers Category Views Company eMail




Answers / { srikanth gowda k }

Question { TCS, 9201 }

Write a program that takes a 3 digit number n and finds out
whether
the number 2^n + 1 is prime, or if it is not prime find out its
factors.


Answer

#include
#include
#include
using namespace std;

int main()
{

int n,a[100];
cout<<"Enter size of the array"< cin>>n;

cout<<"Enter the any value in 3digit format"< for (int i=0;i cin>>a[i];

for (int i=0;i {

if((a[i]/100)>10)
{
cout<<"invaild"< exit(0);
}
}

cout<<"Vaild within 3idigit number"<

int temp=pow(2,a[n-1]);
temp=temp+1;
cout< int count=0;
for(int i=1;i<=1000;i++)
if( (temp)%i == 0 )

{
count++;
}


if (count==2)
{
cout<%2^n+1%"<<"is prime number"< }
else
{
cout< ";
}


return 0;
}

Is This Answer Correct ?    0 Yes 0 No

Question { CTS, 22124 }

Find the maximum product of three numbers in an array?
Eg. 9,5,1,2,3
Max product= 9*5*3= 135
The array can hav negative numbers also..


Answer

#include
#include
using namespace std;

int main()
{
int i,j,a[100];
cout<<"Enter the size of array"< int n;
cin>>n;


if(n==0)
{
cout<<"invaild!!"< exit(1);
}

cout<<"Enter the element for array"< for ( i=0;i cin>>a[i];


int lr=0;
if(n==1)
{
cout<<"only one array is present!!"< exit(0);
}
else if(n==2)
{
if(a[0] {
cout< exit(0);
}

else
{
cout< exit(0);
}
}
else if(n==3)
{
for(i=0;i {
for(j=i+1;j {
if(a[i]*a[j]>lr)
{
lr=a[i]*a[j];

}
}
}

cout<<"max product="< }



else
{
for(i=0;i {
for(j=i+1;j {
for(int k=j+1;k {
if(a[i]*a[j]*a[k]>lr)
{
lr=a[i]*a[j]*a[k];

}
}
}
}

cout<<"max product="< }
return 0 ;
}


/* Ouput

1.

Enter the size of array
5
Enter the element for array
9
5
1
2
3
max product=135

2.

srikanth@srikanth-System-Product-Name:~/c++$ ./a.out
Enter the size of array
5
Enter the element for array
-5
3
1
2
4
max product=24
srikanth@srikanth-System-Product-Name:~/c++$

*/

Is This Answer Correct ?    1 Yes 0 No