[Show all top banners]

lateralus
Replies to this thread:

More by lateralus
What people are reading
Subscribers
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 C++ programming help..
[VIEWED 7104 TIMES]
SAVE! for ease of future access.
Posted on 07-25-07 7:18 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

I need help writing this program in C++....if anyone has some time to write it donw...would really appreciate it.

QUESTION:

Write a c++ program that will ask you for a number.Expect the user to enter only positive integers from 0 to 32,767.Then tell if it is "prime", "not prime" or an "emirp".The program should continue until a zero is entered.Emirps are special cases in prime numbers that are reversed.For example 37 is an emirp because not only it is prime, but so too is 73 (reverse of 37)

The output should consist of a number being investigated followed by the pgrase prime, not prime or emirp.There should be only one result per line.

SAMPLE RUN

Enter a number 37
37 is an emirp.

Enter a number 39
39 is not prime.

Enter a number359
359 is an emirp.

Enter a number 32713
32713 is an emirp.

Enter a number 773
773 is a prime

Enter a number 0.

system("pause") is to be used.

Thanks whoever is interested....
 
Posted on 07-25-07 7:42 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

waaiyaaat!!!
k ho programming assignment ko solution (code) nai online magne? baru ghanta kam garera padhai ma time diyeko bhaye huncha ni..... ki kaso saathi haru? I hope no one will give any help in this matter....
 
Posted on 07-25-07 7:46 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

nicely said Mr.nobody......it is an assignment ....i tried doing it...but got stuck with the emirp thingie..."i hope noone will give any help in this matter re"...haha...alright....
 
Posted on 07-25-07 9:58 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

ok to check if the number is "emrip" or not do the following task-
1. check if the number is prime or not.
2. if the number is prime then reverse it.. like if 37 is the input its reverse will be 73.
3. check if the reverse number is prime too. if it is, then the number is "emrip" otherwise its prime only.

things look pretty easy.... so try iy
 
Posted on 07-26-07 12:12 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Don't remember much of a syntax in C++..I can think only in VBA.
But the logic I can think of for the "emirp" part is:

First:
Convert the Number to String. Probably like this: string B = (string) A.

Second:
Reverse the String using some code (probably the one here:
Third:
Convert target=_blank>http://uw714doc.sco.com/en/SDK_c++/_Reverse.html)

Third:
Convert
the reverse string back to number. (how?)

and then test for prime or no prime.

Other guruz might know better. Good luck.
 
Posted on 07-26-07 12:14 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

how do i reverse a prime number...i.e. how do i get a emrip...---code pls if possible...thanks for the feedback mate..take it easy...peace
 
Posted on 07-26-07 12:35 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

( Found on http site uw714doc.sco.com/en/SDK_c++/_Reverse.html )

String
reverse(String s)
{
String rslt;
for(int i=length(s)-1;i>=0;i--)
rslt += s.char_at(i);
return rslt;
}

See if it reverses a string. But first you have to convert your Number to string.
 
Posted on 07-26-07 12:42 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

or just here...
bluefintuna.wordpress.com/2006/08/18/q10235-simply-emirp/

(googled "emirp algorithm")
 
Posted on 07-26-07 12:43 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Do something like this,
Say you have a prime number,
int i=37
Divide i by 10(integer division)
so
int firstnumber=i/10(=3)
int secondnumner=i-firstnumber*10(remember 10 used is the value of
decimal place of each number. for larger number it will change)
int reversed number=secontNumber*10+firstNumber
 
Posted on 07-26-07 5:53 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

#included

using namespace std;

int main(int argc, char* argv[])
{

int input;
cout << "Enter the number to be checked";
cin >> input;
cout >> process(input);

}

String process (int input)
{
cout >> " This seems to be simple program...Try to do yourself..";
cout >> "Feeding with spoon is bad for health";
cout >> " Abnormal Program Termination"+ int(1/0);
exit(0);

}
 
Posted on 07-26-07 6:24 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

actually i finally fixed the problem...and the program ran well...thanks for your guy's help...peace.....now finally i can smoke dem wicked joints of time...later....peace.............
 
Posted on 07-28-07 3:51 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

could u please show me how u did it....im havin lots of trouble and i cant get it right...
 


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 200 days
Recommended Popular Threads Controvertial Threads
TPS Re-registration case still pending ..
ChatSansar.com Naya Nepal Chat
Toilet paper or water?
TPS EAD auto extended to June 2025 or just TPS?
Biden out, Trump next president, so what’s gonna happen to TPS, termination?
and it begins - on Day 1 Trump will begin operations to deport millions of undocumented immigrants
मन भित्र को पत्रै पत्र!
Tourist Visa - Seeking Suggestions and Guidance
From Trump “I will revoke TPS, and deport them back to their country.”
Anybody gotten the TPS EAD extension alert notice (i797) thing? online or via post?
advanced parole
TPS Renewal Reregistration
Sajha Poll: Who is your favorite Nepali actress?
Biden said he will issue new Employment visa for someone with college degree and job offers
Why Americans reverse park?
Nepali Passport Renew
Driver license help ASAP sathiharu
They are openly permitting undocumented immigrants to participate in federal elections in Arizona now.
ढ्याउ गर्दा दसैँको खसी गनाउच
To Sajha admin
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