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....... |
Why not do this in Perl? :twocents:
#!/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"; |
All times are GMT -5. The time now is 05:53 AM. |