Strong Number In C - C Programming Tutorial
C Course / Programs / Strong Number In C

Strong Number In C

BLUF: Understanding Strong Number In C is a foundational part of learning C programming. This tutorial explains the core principles and syntax needed to implement this concept effectively.
Core Programming Principle: Strong Number In C

C provides direct access to memory and system resources. Learn how Strong Number In C leverages this power in the lesson below.

Let's illustrate with a practical demonstration.

  • Code to verify if a number is a strong number or not.
Example

#include <stdio.h>
int main()
{
    int n;
    int sum=0;
    printf("Enter a number");
    scanf("%d",&n);
    int k=n;
    int r;
    while(k!=0)
    {
        r=k%10;
        int f=fact(r);
        k=k/10;
        sum=sum+f;
    }
    if(sum==n)
    {
        printf("\nNumber is a strong");
    }
    else
    {
        printf("\nNumber is not a strong");
    }
    return 0;
}
int fact(int r)
{
    int mul=1;
    for(int i=1;i<=r;i++)
    {
        mul=mul*i;
    }
    return mul;
    
}

In the provided code snippet, the user's input data is first captured, followed by a validation process to determine if the input constitutes a strong number.

Output

Output

Enter a number
Number is a strong
Number is not a strong
  • Program to print the strong numbers from 1 to n.
Example

#include<stdio.h>
int main()
{
    int fact=1,sum=0;
    int n,r;
    printf("Enter the 'n' number");
    scanf("%d",&n);
    printf("\n Strong numbers are :");
    for(int i=1;i<=n;i++)
    {
        int k=i;
        while(k!=0)
        {
            r=k%10;
            fact=factorial(r);
           
        
            k=k/10;
            sum=sum+fact;
        }
        if(sum==i){
        printf("%d, ",i);
        
           }
           sum=0;
    }
    
   
    return 0;
}

 int factorial(int f)
    {
        int mul=1;
        for(int i=1; i<=f;i++)
        {
            mul=mul*i;
        }
        return mul;
    }

Output

Output

Enter a number
Number is a strong
Number is not a strong

Develop a script to identify strong numbers within a specified range.

Example

#include<stdio.h>
int main()
{
    int fact=1,sum=0;
    int n1,n2,r;
    printf("Enter the first number");
    scanf("%d",&n1);
    printf("\nEnter the last number");
    scanf("%d",&n2);
    printf("\nStrong numbers are :");
    for(int i=n1;i<=n2;i++)
    {
        int k=i;
        while(k!=0)
        {
            r=k%10;
            fact=factorial(r);
            k=k/10;
            sum=sum+fact;
        }
        if(sum==i){
        printf("%d, ",i);
        }
           sum=0;
    }
   return 0;
}
int factorial(int f)
 {
        int mul=1;
        for(int i=1; i<=f;i++)
        {
            mul=mul*i;
        }
        return mul;
    }

Output:

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience