Que- If a five digit number is input through the keyboard, write a program to reverse the number. - void main()
-
{
-
int num=12345, res=0, rem;
-
clrscr();
-
while(num > 0)
-
{
-
rem=num% 10;
-
res=res* 10 + rem;
-
num=num/10;
-
}
-
printf("Reverse of a number=%d",res);
-
getch();
-
}
According to me logic is rite, but the result coming out to be is not correct... Check it our,,, & reply
10 4215 Que- If a five digit number is input through the keyboard, write a program to reverse the number.
void main()
{
int num=12345, res=0, rem;
clrscr();
while(num > 0)
{
rem=num% 10;
res=res* 10 + rem;
num=num/10;
}
printf("Reverse of a number=%d",res);
getch();
}
According to me logic is rite, but the result coming out to be is not correct... Check it our,,, & reply
It should (and does) work.
If we enter the number upto four digit,answer is rite, Suppose I enter 1234 Answer is 4321.
But If we enter five digit numb,suppose 12345, Answer is not coming 54321.
If we declare num as long, even then the o/p is not coming out to be correct for 5 digit number.
Far be it from me to doubt you, but I copied and pasted your code into an editor and compiled it, and it produced the desired output.
Ok thx, but i face still d same probs.
Exactly what output are you getting?
e.g. You enter 12345.
What is output?
When I enter 12345, answer is -11215.
When I enter the numb upto 4 digit, answer is coming correct.
When I enter 12345, answer is -11215.
When I enter the numb upto 4 digit, answer is coming correct.
The ints on your system are two bytes wide so they can only store numbers in
the range [-2^15,2^15-1], e.g. the number 54321 - 2^15 == -11215, so your
algorithm is correct, the ints are just to narrow (try four byte longs).
kind regards,
Jos
then wat to do to get the correct answer of Five digit number,,,,,,,Even if I declare the numb as long datatype.........even then the answer is not coming out to be correct
then wat to do to get the correct answer of Five digit number,,,,,,,Even if I declare the numb as long datatype.........even then the answer is not coming out to be correct
Make all your variable long ints and print them as such: %ld instead of %d.
kind regards,
Jos
Dear Sonia.;
ur code is absolutely correct. firstly check ur compiler size n gv 3/4 digit num.
as it is working in my sys. i.e visual studio..
ck it out n info.
Regards
Vicky...
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Brad Tilley |
last post by:
A friend of mine wrote an algorithm that generates strings. He says that
it's impossible to figure out exactly how the algorithm works. That may
be true, but I think if I had enough sample strings...
|
by: google |
last post by:
I'm trying to implement something that would speed up data entry. I'd
like to be able to take a string, and increment ONLY the right-most
numerical characters by one. The type structure of the...
|
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...
|
by: rick |
last post by:
Why can't Python have a reverse() function/method like Ruby?
Python:
x = 'a_string'
# Reverse the string
print x
Ruby:
x = 'a_string'
# Reverse the string
|
by: schaf |
last post by:
Hi NG!
I have a problem in my remote application.
After calling a remote function the calculation will be done by the
service. The calculation result will be sent to the caller (client)
via...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
| |