[Show all top banners]

helpjava11
Replies to this thread:

More by helpjava11
What people are reading
Subscribers
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 Programming Challenge 1
[VIEWED 3900 TIMES]
SAVE! for ease of future access.
Posted on 06-25-14 1:08 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 



You are given a function ‘secret()’ that accepts a single integer parameter and returns an integer. In your favorite programming language, write a program that takes one argument (a number) and determines if the secret() function is additive [secret(x+y) = secret(x) + secret(y)], for all values x and y, where x and y are prime numbers less than the 100.
 
Posted on 06-25-14 1:34 PM     [Snapshot: 45]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

public static bool isPrime(int number)
{

for (int i = 2; i < number; i++)
{
if (number % i == 0)
{
return false;
}
}

return true;
}

public int secret(int x)
{
if ((x < 100) && isPrime(x))
return (x);
else return (0);
}

private void button1_Click(object sender, EventArgs e)
{
int val1=secret(Convert.ToInt32(textBox1.Text));
int val2 = secret(Convert.ToInt32(textBox2.Text));

if (val1 == 0 || val2 == 0)
{
label1.Text = "Prime number and between 0 to 100 please";
return;
}

int final = Convert.ToInt32(textBox1.Text) + Convert.ToInt32(textBox2.Text);
int val3 = secret(final);
if (val3 == val1 + val2)
{
label1.Text = "Perfect!!!";
}

}
 
Posted on 06-25-14 2:18 PM     [Snapshot: 102]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Am I missing something here?

Is this sort-of puzzle question or just simple programming one? If the latter then batman's response is on the money. It first adds two numbers entered and it then checks whether the sum is the sum of the two numbers; ofcourse the answer will be always "Perffect!!!", unless some one doesn't enter the number correctly.

My guess is that there is something more to the question. Definition of additive is too simple, did you mean something else?
 
Posted on 06-25-14 3:54 PM     [Snapshot: 178]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Kiddo bro, this is not puzzle. Conpletely coding . This is copy paste from one of the interview i took some time back.
 
Posted on 06-25-14 9:33 PM     [Snapshot: 294]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Is there some relation between "one argument (a number)" and (x, y) (or 100)?
Last edited: 25-Jun-14 09:34 PM

 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 7 days
Recommended Popular Threads Controvertial Threads
TPS Re-registration case still pending ..
ढ्याउ गर्दा दसैँको खसी गनाउच
जाडो, बा र म……
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters