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.
Ask a Question
Ask a Question
the following code was supposed to display all strong numbers in a given limit but it is not giving any output, why?
Jun 7, 2018
Jun 30, 2018
int n,i,r,sum =0,fact,limit; // it doesn't display any results
printf("Enter number = ");
r = n%10;
fact = 1;
fact = fact*i;
sum = sum + fact;
printf("%d strong number",n);
closed with the note:
the answer by the below user is sufficient
Jun 14, 2018
First, you have an infinite loop in your program.
trace the value of n, first it is 1, then the while loop sets it to zero again and then adds 1 to in the for loop
Second, you never reset your accumulator to zero.
Third, your check is comparing n, which is zero, to your sum, which can never be zero because 0! = 1.
for( num = 1; num <= limit; num++)
n = num;
sum = 0;
// your while loop
if( num == sum )
printf( "%d is a strong number\n", num );
Your comment on this answer:
Your name to display (optional):
Email me at this address if a comment is added after mine:
Email me if a comment is added after mine
Privacy: Your email address will only be used for sending these notifications.
To avoid this verification in future, please
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.
Snow Theme by