/ * Strong Number * /
Definition :A number is called strong number if sum of it's factorials of it's digits is equal to number itself.
Example : 145
= 1! + 4! + 5!
= 1+24+120
=145
#include<stdio.h>
#include<conio.h>
void main( )
{
int n, i, f, r, sum=0, tmp;
clrscr( ) ;
printf(" Enter any number ") ;
scanf("%d", &n) ;
tmp=n;
while(n) or while (n! =0)
{
i=1 ;
f=1 ;
r=n%10 ;
while (i<=r)
{
f=f * i ;
i ++ ;
}
sum=sum+f ;
n=n/10 ;
}
if(sum==tmp)
printf("\n%d is Strong number ", tmp) ;
else
printf(“\n%d is not a strong number", tmp) ;
getch ( );
}
/ * Strong number range in between min &max */
#include<conio.h>
void main( )
{
long int min, max, n, i, f, r, sum,tmp;
clrscr( ) ;
printf(" \nEnter minimum number ") ;
scanf("%ld",&min) ;
printf("\n Enter maximum number ") ;
scanf("%ld",&max) ;
printf("\nStrong numbers are:") ;
for(n=min;n<=max;n++)
{
tmp=n;
sum=0;
while (tmp)
{
i=1 ;
f=1 ;
r=tmp%10 ;
while (i<=r)
{
f=f * i ;
i ++ ;
}
sum=sum+f ;
tmp=tmp/10 ;
}
if(sum==n)
printf("\n%ld is Strong number", n);
}
getch ( );
}
Output:
1 2 145 40585
/* Armstrong Number */
Definition:- Those number whose sum of its digits to power of number of its digits is equal to that number is known as Armstrong number.
For example : 153, 370, 371
Total Digits in 153 is 3
And 13 +53+33 =1+125+27=153
For example : 1634
Total Digits in 1634 is 4
And 14+64+34+44=1+1296+81+256 =1634
#include<stdio.h>
#include<conio.h>
void main( )
{
int n,r, sum=0,tmp ;
clrscr( ) ;
printf(“Enter any number:”) ;
scanf(“%d”,&n) ;
tmp=n ;
while(n)
{
r=n%10 ;
n=n/10 ;
sum=sum+(r*r*r*) ;
}
if(sum==tmp)
printf(“\n%d is an Armstrong number”,tmp) ;
else
printf(“\n%d is not an Armstrong number”,tmp) ;
getch( ) ;
}
#include<stdio.h>
#include<conio.h>
void main( )
{
int min,max,n,sum=0,r,tmp ;
clrscr( ) ;
printf(“\nEnter min number:”) ;
scanf(“%d”,&min) ;
printf(“\nEnter max number:”) ;
scanf(“%d”,&max) ;
printf(“\n Armstrong number is the given range :”) ;
for( n=min ; n<=max ; n++)
{
tmp=n ;
sum=0 ;
while(tmp!=0)
{
r=tmp%10 ;
tmp=tmp/10 ;
sum=sum+(r*r*r) ;
}
if(sum==n)
printf(“\n%d is Armstrong number”,n) ;
}
getch( ) ;
}
/*Perfect Number*/
Definition:-Perfect number is a positive number whose sum of all positive divisors excluding that number is equal to that number is known as Perfect number.
For example: 6 is a perfect number , since divisor of 6 are 1,2 and 3. Sum of it's divisor is 1+2+3= 6
28=> 1,2,4,7,14 1+2+4+7+14 = 28
496,
8128.
#include<stdio.h>
#include<conio.h>
void main( )
{
int n,i=1,sum=0,tmp ;
clrscr( ) ;
printf(“Enter any number:”) ;
scanf(“%d”,&n) ;
tmp=n ;
while(i<n)
{
if (n%i ==0)
sum=sum+i ;
i++;
}
if(sum==tmp)
printf(“\n%d is an Perfect number”,tmp);
else
printf(“\n%d is not an Perfect number”,tmp);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int min,max,n,sum=0,i,tmp ;
clrscr() ;
printf(“\nEnter min number:”) ;
scanf(“%d”,&min) ;
printf(“\nEnter max number:”) ;
scanf(“%d”,&max) ;
printf(“\nPerfect number is the given range:”) ;
for(n=min;n<=max;n++)
{
i=1 ;
sum=0 ;
while(i<n)
{
if(n%i==0)
sum =sum+i ;
i++ ;
}
if (sum ==n)
printf("\n%d is Perfect number”, n) ;
}
getch ( ) ;
}
/*Prime number*/
Definition:- A natural number greater than one has not any other divisors except 1 and itself.In other word we can say which has only two divisors 1 and number itself.
For example:- 5 divisiors are 1 and 5.
#include<conio.h>
void main( )
{
int n,i=1,count=0 ;
clrscr( ) ;
printf("Enter any number") ;
scanf("%d",&n) ;
while(i <= n)
{
if( (n%i==0) && (n%n==0) )
count++ ;
i++ ;
}
if(count==2)
printf("\n%d is a Prime number",n) ;
else
printf("%d is not a prime number",n) ;
getch( ) ;
}
#include<stdio.h>
#include<conio.h>
void main()
{
int min,max,n,i,count;
clrscr( );
printf("\nEnter min number");
scanf("%d",&min);
printf("\nEnter max number");
scanf("%d",&max);
printf("\nPrime number in the given range:");
for(n=min ; n<=max ; n++)
{
i=1;
count=0;
while(i<=n)
{
if( (n%i==0) && (n%n==0) )
count++;
i++;
}
if(count == 2)
pf("\n%d is Prime number”,n);
}
getch( );
}
/*Magic number*/
Definition:-A number is said to be a magic number if the reverse of the square of the number is equal to the given number reverse and its square.
#include<stdio.h>
#include<conio.h>
void main ()
{
int , i ,j,k,n ;
clrscr( ) ;
printf(“Enter any number”) ;
scanf(“%d”, &n) ;
while (i>n)
{
i=n*n ;
j=0 ;
while(i>0)
{
j=j * 10 + i % 10 ;
i = i / 10 ;
}
i=n ;
k=0 ;
while(i>0)
{
k=k*10+i%10 ;
i=i/10 ;
}
if(k*k==j)
printf (“\nMagic number”) ;
else
printf (“\nNot a Magic number” ) ;
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main ( )
{
int i,j,k,n,min,max ;
clrsccr() ;
printf (“\nEnter min number “) ;
scanf(“%d”,&min );
printf (“\nEnter max number” ) ;
scanf(“%d”,&max) ;
for (n=min; n<=max ; n++)
{
i=n*n ;
j=0 ;
while(i>0)
{
j=j * 10 + i % 10 ;
i = i / 10 ;
}
i=n ;
k=0 ;
while(i>0)
{
k=k*10+i%10 ;
i=i/10 ;
}
if (k * k == j)
printf (“\n%d is a Magic number” , n );
}
getch() ;
}
/*Palindrome number */
Definition: A number is caller palindrome number if it remain some when it's digits are reversed
For Example : 121 is palindrome number, when we will increase ln digit it will remain same number i. e 121
#include <stdio.h>
#include <conio.h>
void main( )
{
int n, r, tmp, sum=0 ;
clrscr( ) ;
printf(" Enter any number ") ;
scanf("%d ", &n) ;
tmp=n ;
while (tmp)
{
r=n%10 ;
r=n/10 ;
sum= sum * 10 +r ;
}
if (sum ==tmp)
printf("\n%d is a Palindrome number ", tmp) ;
else
printf("\n%d is not a Palindrome number ",) ;
getch( ) ;
}
#include<stdio.h>
#include<conio.h>
void main ( )
{
int min, max, n, r,sum=0, tmp ;
clrscr( ) ;
printf ("\nEnter min number: ") ;
scanf(“%d”,&min) ;
printf(“\nEnter max number:”) ;
scanf ("%d", &max) ;
printf (" \nPalindrome number in the given range ") ;
for ( n=min, n<=max; n++)
{
tmp=n ;
sum=0 ;
while (tmp)
{
r=tmp%10 ;
tmp=tmp/10 ;
sum=sum * 10 + r ;
}
if (sum==n)
printf ("\n%d is Palindrome number ", n) ;
}
getch( ) ;
}
#include<stdio.h>
#include<conio.h>
void main( )
{
int n,r,tmp,rev=0,sum=0;
clrscr( );
printf("Enter any number");
scanf("%d",&n);
tmp=n;
while(n)
{
r=n%10;
n=n/10;
rev=rev*10+r;
sum=sum+r;
}
printf("\n%d Reverse number is %d:",tmp,rev);
printf("\n sum of the reverse number is %d:",sum);
getch( );
}
#include<stdio.h>
#include<conio.h>
void main( )
{
int n,f=1,tmp;
clrscr( );
printf("Take any number");
scanf("%d",&n);
tmp=n;
while(n)
{
f=f*n;
n--;
}
printf("\n%d factorial is %d",tmp,f);
getch( );
}
output :- Enter any number : 4
4 factorial is 24
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int n;i,past=0,present=1,future;
clrscr();
printf(“enter any number: “);
scanf(“%d”,&n);
printf(“%d%d”,past,present);
future=past+present;
printf(“%d”,future);
for(i=0;i<n-3;i++)
{
past=present;
present=future;
future = past + present;
printf("\t %d", future );
}
getch();
}
Input: n=5
Output: 0 1 1
Past present future
0 1 1 2
Past present future
0 1 1 2 3
Past present future
No comments:
Post a Comment