to check given number is magic or not, what wrong in my code? in c

+6 votes
asked Sep 22 by Tarun Kumar Tarlana (200 points)
#include <stdio.h>
int rnum(int number);
int main()
{int num,temp,x,sum1=0,sum2;
    printf("Hello World\nenter the number ");
        printf("%d is a magic number",num);
    return 0;

    int rnum(int number)
    {int rnumber=0,x;
    {   x=number%10;
    return rnumber;

1 Answer

–1 vote
answered Sep 22 by Peter Minarik (12,220 points)

First of all, it's nice to describe what your problem is.

Second, it's also nice to explain what your program is supposed to do. In this instance, explain the definition of what you mean by "magic number".

I've found a problem in rnum() where you can easily end up in an infinite loop:


I think what you wanted to write was:

number /= 10; // i.e. number = number / 10;

Now your code runs, not ending up in an infinite loop.

commented Sep 22 by Tarun Kumar Tarlana (200 points)
thanks brother
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.