The problem is input a number then the output should be in reverse order..
I already made a code but only good for 9 - digit only...What I want to do is to hold infinite digit, in other words don't have a limit on how many digit that I want to input..
for (x = y;x>0;x=x/10){
z = x % 10;
cout<<z;
}
* code good for 9 - digit only, if I input 10 digit its output is not correct anymore..I used int as data type
Pls. Help
6 6887 - Code has been removed. Please see our Posting Guidelines.
-
-
MODERATOR
In recursion we trust!
Just call revhat() with your number.
What's revhat()? could you please elaborate more? - Code has been removed. Please see our Posting Guidelines.
-
-
MODERATOR
In recursion we trust!
Just call revhat() with your number.
Ganon11 3,652
Recognized Expert Specialist
That post had some full code, which is not allowed (see our Posting Guidelines).
I'm having trouble understanding why this code doesn't work universally...
Ganon11 3,652
Recognized Expert Specialist
This simple code compiled: - #include <iostream>
-
using namespace std;
-
-
int main() {
-
cout << "Please enter a number: ";
-
int y;
-
cin >> y;
-
cout << endl;
-
-
int x, z;
-
-
for (x = y; x > 0; x /= 10){
-
z = x % 10;
-
cout << z;
-
}
-
cout << endl;
-
return 0;
-
}
-
and produced the following result: - $ digit.exe
-
Please enter a number: 1231231231
-
-
1321321321
Anything more than 10 digits was not working - possibly because you are exceeding the maximum amount for an int?
Ganon11 3,652
Recognized Expert Specialist
EDIT: After a few more test runs, I'm sure of it. The maximum value for an int is something like 2,148,000,000, which is 10 digits. If you input anything greater than that, your program won't work (because an int isn't big enough to hold that). This is an expected error, so I wouldn't worry about it. If you need to use numbers bigger than 10 digits, try a long int.
What's revhat()? could you please elaborate more?
I am sorry but code was deleted by moderator.
I provided code implementing following recursive algorithm :
revrec() function takes an integer argument :
if it is not 0 then last digit is printed and revrec() is called again with argument divided by 10.
The revhat() function is intended to check if initial argument is 0, in which case it is printed. Else, revrec() is called with argument.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: - |
last post by:
Hi,
If I have a simple for loop like this:
for a in b:
print a
Is there a way I can get the next element in the loop? Something like this:
for a in b:
|
by: Rajorshi Biswas |
last post by:
Hi folks,
Suppose I have a large (1 GB) text file which I want to read in
reverse. The number of characters I want to read at a time is
insignificant. I'm confused as to how best to do it. Upon browsing
through this group and other sources on the web, it seems that there
are many ways to do it.
Some suggest that simply fseek'ing to 8K bytes before the end of file,
and going backwards is the way. In this case, am I guaranteed best
results...
|
by: Vedran Vukotic |
last post by:
Hello
I made the following infinite loop that check's if the bot died and call
it again:
------loadloop.pl-----
#!/usr/bin/perl
use strict;
while (1) {
|
by: aatish19 |
last post by:
1: Write a program that asks the user to input an integer value and
print it in a reverse order
Sample Output
Enter any number 65564
Reverse of 65564 is 46556
2: Write a program that takes a string as an input and print it in
reverse order.(don't use bulit-in/library function).
Sample Output
Enter any string: i m Kashif
|
by: raghuveer |
last post by:
i want to print my linked list in the reverse order ie..last item first and first item last..this is what i have so far
struct linked_list
{
int number;
struct linked_list *next;
};
typedef linked_list node;
| |
by: nabman |
last post by:
I am reading a txt file, I have a txt file(customers.txt) that is read, with account numbers and passwords. Once the user enters a account number and password it should read the file and if there in there it will show the second form and end the loop. The probelm I am having is when I enter a acct # and password that is maybe the third entry in the file it is hitting the "else" statment and displaying my msgbox. What is the code I can put in...
|
by: Dubs |
last post by:
Hi i need to find the GC content in a number of files i have a code which works but would like to shorten it, at the moment i have the same piece of script repeated 8 times but would like to add a loop instead, however every time i try it crashes the program.
@Name;
@Seq;
open FILE,"YBL091C.data";
($NoSeq,$size) = split(/ /,<FILE>);
|
by: Alex Snast |
last post by:
Hello
I'm new to python and i can't figure out how to write a reverse for
loop in python
e.g. the python equivalent to the c++ loop
for (i = 10; i >= 0; --i)
|
by: JWest46088 |
last post by:
I'm having difficulty trying to figure out how to print a text file from a hash table one line at a time. I have the text file read into the hash table and can print the text file all at once, but I can't seem to figure out how to do it one line at a time.
Here is what I'm trying to do: I want the user to be able to print the text file one line at a time by clicking a button to see the next line.
Example: If text_file1 first line is...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |