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.

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

+18 votes
asked Apr 20 by Mufeeda Mufeeda (250 points)
closed May 19 by Admin

#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;
}

closed with the note: answered

4 Answers

+7 votes
answered Apr 22 by Peter Minarik (88,520 points)
selected May 19 by Admin
 
Best answer

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;
}
0 votes
answered Apr 30 by danish khan (140 points)
you are lacking in loop condition you must  be use while(n>0) then your code is work
0 votes
answered May 8 by GNANESHWARAN V (150 points)

#include <stdio.h>

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

0 votes
answered May 10 by aditi tiwari (180 points)
#include <stdio.h>

int main()
{
    int n, rev = 0, rem, temp;
    printf("Enter a number: ");
    scanf("%d", &n);
    temp = n;

    while (n > 0) {
        rem = n % 10;
        rev = (rev * 10) + rem;
        n = n / 10;
    }

    printf("Reverse of %d is %d\n", temp, rev);

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