954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

reversing long integers,, newbie,, pls. help

hey,, i'm joyce, newbie.. I am very stuck in this problem,, had been on it in days. I've tried many prgrams but none seemed to work properly.
the objective is to use a function that displays a reversed version of a long integer. e.g. 12345 then display 54321.

Out of all the programs i did, i think this is the 'best' of the worst...

#include <stdio.h>
#include <conio.h>
int reverse(int num)
{
long sum=0;
int rem;
while (num=0)
{
rem=num%10;
sum=sum*10+rem;
num=num/10;
return (sum);
}
main()
{
int num, sum;
printf ("enter a no. to be reversed:");
scanf ("%d", &num);
reverse(int num);
printf ("%d", sum);
getche();
}



im sorry if i doubled stuff because i am both new to functions and forums,,, please,, i need help. IF I DON'T GET HELP, I'M GONNA FAIL COMPUTER SCIENCE...............

joyce_16jo
Newbie Poster
1 post since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

>>hey,, i'm joyce, newbie

Welcome to DeniWeb. Please go to the CoffeeHouse and tell us about yourself.

As for your problem if it were me I would convert the integer to a character string then just print the string backwards. You can use sprintf() to make the conversion.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

> while (num=0)
Use == for comparison, = is for assignment
Though you probably want !=

> return (sum);
Think - would this be better inside or outside of the loop.

> reverse(int num);
This just prototypes the function again.
Try say
sum = reverse( num );

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You