Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

what is it's error it is not running.please found to me.

+7 votes
asked Apr 20 by Mufeeda Mufeeda (190 points)

#include <stdio.h>

int main()
{
    int n,rev=0,rem,temp;
    printf("Enter a number");
    scanf("%d",&n);
    temp=n;
    
    for(0<n;
    
       rem=n%10;
        rev=(rev*10)+rem;
        n=n/10; }
    
    printf("value of %d is %d",rev,temp);
    
    return 0;
}

1 Answer

+5 votes
answered Apr 22 by Peter Minarik (86,640 points)
edited Apr 23 by Peter Minarik

Instead of the for statement for your loop you should (correctly) use the while statement:

while (0 < n)

That should get your problem sorted.

You should also consider giving more talkative variable names. Your code would look something like this after some clean-up:

#include <stdio.h>

int main()
{
    int number;
    printf("Enter a number to reverse its digits: ");
    scanf("%d", &number);
    int temp = number;
    int reverse = 0;    
    while (0 < temp)
    {
        int remainder = temp % 10;
        reverse = reverse * 10 + remainder;
        temp /= 10;
    }    
    printf("Reverse of %d is %d.\n", number, reverse);
    return 0;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...