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.

Hello,i m begginner in C programming .can you guys tell me what's wrong with this program?

+3 votes
asked May 22, 2020 by A kan (220 points)

//a program to check whether the given number  is strong number or not
#include<stdio.h>
void main()

{

 //declaring variables
     int re;  //remainder
     int copy;  
     int i;  //counter
     int num; 
     int fact; //factorial
      fact=1; 
      int sum; //sum
      sum=0;
 //taking input
     printf("enter your number:\n");       
     scanf("%d",&num);
     copy=num; //storing the value of num to copy variable
 
    while(copy!=0)
    {

         re=copy%10;  
       for(i=1;i<=re;i++); 
         {
             fact=fact*i;}   

             sum=sum+fact;    
             fact=1;        
              copy=copy/10;   

}

       if(sum==num)
       printf("%d is the  strong number\n",num );

       else
       printf("%d is not strong number\n",num);


}

3 Answers

+4 votes
answered May 25, 2020 by Godwin 219729 (220 points)

The syntax for the for loop is wrong. It should not have a semicolon.

for(i=1;i<=re;i++) /*NO SEMICOLON*/

commented May 27, 2020 by Rahul Choubey (550 points)
This seems like the right answer, although the asker does not mention a specific error.
commented May 29, 2020 by A kan (220 points)
yeah! now i got it.
Thank you so much .
+2 votes
answered May 29, 2020 by Amit Pandey (230 points)
your code is absolutely fine and showing correct output when number is 145(for as an example)

the problem is that YOU SHOULD REMOVE THAT SEMILCOLON WHICH U INSERTED TO FORLOOP
0 votes
answered May 29, 2020 by AA GAMER (140 points)

%d is the  strong number\n",num

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