LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-15-2003, 08:37 AM   #1
narendra_i
LQ Newbie
 
Registered: Sep 2003
Location: hyderabad
Posts: 12

Rep: Reputation: 1
reversing a number


how to take a number from input
and reverse it


int sum=0,t=1;
char ch;
scanf("%c",&ch);
while(ch!='.')
{
sum=sum+(ch-'0')*t;
t=t*10;
scanf("%c",&ch);
}
printf("%d",sum);


the abvove code works with a '\n' (or) '.'
can i write a funtion tom reverse it with out using . or \n;



waiting for u r reply.......
 
Old 11-15-2003, 09:25 AM   #2
TheOther1
Member
 
Registered: Feb 2003
Location: Atlanta, GA
Distribution: RHAS 2.1, RHEL3, RHEL4, SLES 8.3, SLES 9, SLES9_64, SuSE 9.3 Pro, Ubuntu, Gentoo
Posts: 335

Rep: Reputation: 32
Why not do this in Perl?

#!/usr/bin/perl -w
use strict;
my $digit;
print "Enter number:";
$digit = <STDIN>;
chomp $digit;
print "Number = $digit\n";
$digit = (reverse $digit);
print "Reverse Number = $digit\n";

If want to cut this script down even more:

#!/usr/bin/perl -w
print "Enter number:";
$digit = <STDIN>;
chomp $digit;
$digit = (reverse $digit);
print "Reverse Number = $digit\n";
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
reversing rrdtool graphs whysyn Linux - Software 0 06-05-2005 04:31 PM
reversing connectors on SCSI cable randyding Linux - Hardware 1 04-08-2005 05:26 PM
reversing program greenthing Programming 3 02-27-2005 08:08 PM
java, reversing digit Lifesaver Programming 5 03-03-2004 04:09 PM
reversing videocard lackluster Linux - Hardware 1 11-16-2002 02:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration