Question about functions in C

I've written this program in C that asks for an integer input and outputs the numbers in reverse order. I need to cut the loop out of it into a separate function that is called upon, but I'm having trouble getting it to work. Any suggestions about how to make a function out of a part of the code?

#include
int main( void )
{

int num, mod, rev = 0;

printf("
");
printf("Enter an Integer Between 1 - 10,000: ");
scanf("%d", &num);
printf("
");

while( num > 0)
{
mod = num %10;
rev = (rev * 10) +mod;
num = num / 10;
}

printf(" The Reverse of the Integer is: %d
", rev);

return 0;
}

Comments

  • [code]
    #include

    int reverse(int num)
    {
    int mod, rev = 0;
    while( num > 0)
    {
    mod = num %10;
    rev = (rev * 10) +mod;
    num = num / 10;
    }
    return rev;
    }

    int main( void )
    {
    int num;

    printf("
    ");
    printf("Enter an Integer Between 1 - 10,000: ");
    scanf("%d", &num);
    printf("
    ");

    printf(" The Reverse of the Integer is: %d
    ", reverse(num));

    return 0;
    }
    [/code]
  • Can u help me about my C++ running program,here is my Proble.
    Write a Program that outputs the balance of an account after each succeding year.The input is the initial balance,the interest rate,the first year,and the last year.Assume the deposit is made on January 1 and the interest for the pastyear is calculated and paid once each year on January 1.Next modify the program so that it shows three different balances for different ways of calculating the interest;simple interest, compounded semiannually,and compounded quarterly.Finally,modify the Program so that it allows the user to repeat this calculation as often as desired.



  • Can u help me about my C++ running program,here is my Proble.
    Write a Program that outputs the balance of an account after each succeding year.The input is the initial balance,the interest rate,the first year,and the last year.Assume the deposit is made on January 1 and the interest for the pastyear is calculated and paid once each year on January 1.Next modify the program so that it shows three different balances for different ways of calculating the interest;simple interest, compounded semiannually,and compounded quarterly.Finally,modify the Program so that it allows the user to repeat this calculation as often as desired.



Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories