Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C# Sharp Exercises: Find Strong Numbers within a range of numbers

C# Sharp For Loop: Exercise-48 with Solution

Write a C# Sharp program to find Strong Numbers within a range of numbers.

Pictorial Presentation:

C# Sharp Exercises: Find Strong Numbers within a range of numbers

Sample Solution:

C# Sharp Code:

using System;  
public class Exercise48
{  
    public static void Main()  
{  
    int i, n1, s1=0,j,k,en,sn;  
    int fact; 
	
	Console.Write("\n\n");
    Console.Write("Find Strong Numbers within a range of numbers:\n");
    Console.Write("------------------------------------------------");
    Console.Write("\n\n");	


/* If sum of factorial of digits is equal to original number then it is Strong number */
  
    Console.Write("Input starting range of number : ");  
    sn = Convert.ToInt32(Console.ReadLine());	
    Console.Write("Input ending range of number: ");  
    en = Convert.ToInt32(Console.ReadLine());	
    Console.Write("\n\nThe Strong numbers are :\n"); 

 for(k=sn;k<=en;k++)
   {
     n1=k;
     s1=0;  
 
    for(j=k;j>0;j=j/10) 
    {  
  
        fact = 1;  
          for(i=1; i<=j % 10; i++)  
           {  
            fact = fact * i;  
           }  
            s1 = s1 + fact;  
    }  
  
    if(s1==n1)  
       
        Console.Write("{0}  ", n1); 
  }  
        Console.Write("\n\n"); 
}  
} 
 

Sample Output:

Find Strong Numbers within a range of numbers:                                                              
------------------------------------------------                                                            
Input starting range of number : 0                                                                          
Input ending range of number: 1000                                                                          
The Strong numbers are :                                                                                    
0  1  2  145

Flowchart:

Flowchart: Find Strong Numbers within a range of numbers

C# Sharp Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a C# Sharp program to check whether a number is Strong Number or not.
Next: Write a C# Sharp program to find out the sum of in A.P. series.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.