0

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...............

3
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by Salem
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.

0

> 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 );

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.