Pages

Saturday, 2 February 2019

PROGRAM TO FIND WHETHER THE GIVEN NUMBER IS MAGIC NUMBER OR NOT

/*PROGRAM TO FIND WHETHER THE GIVEN NUMBER IS MAGIC NUMBER OR NOT*/

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

for eg: (12) sqaure =144 reverse of 144 is 441
            (21) square= 441

             (13) square=169 reverse of 169 is 961
             (31) sqaure=691

program:

// prg to illustrate magic number

#include<stdio.h>
void main()

{

 int j,i,k,n,temp;

 printf("\nENTER ANY NUMBER:");

 scanf("%d",&n);
 temp=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("\n%d is a Magic number\n ",temp);
    else
         printf("\n%d is not a Magic number\n ",temp);
  }
}
output:


MAGIC NUMBER IN BETWEEN MIN AND MAX VALUES

/*PROGRAM TO FIND WHETHER THE GIVEN NUMBER IS MAGIC NUMBER OR NOT*/

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

for eg: (12) sqaure =144 reverse of 144 is 441
            (21) square= 441

             (13) square=169 reverse of 169 is 961
             (31) sqaure=691

program:
// prg to illustrate magic number in between min and max values

#include<stdio.h>
void main()

{

 int min,max,j,i,k,n;

 printf("\nEnter min value:");

 scanf("%d",&min);

 printf("\nEnter max value:");

 scanf("%d",&max);
 printf("\nMagic numbers are:");

 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 ",n);
   
}
}


output:

STRONG NUMBERS IN BETWEEN MIN AND MAX VALUES

// program to illustrate strong number in between min and max values

#include<stdio.h>
void main()
{
  int min,max,n,i,r,sum=0,temp,fact;
  printf("\nEnter min value:");
  scanf("%d",&min);
  printf("\nEnter max value:");
  scanf("%d",&max);
  printf("\nStrong numbers are:");
   for(n=min ;n<=max;n++)
   {
     temp=n,sum=0;
     while(temp)
     {
       i=1,fact=1;
       r=temp %10;
         while(i <= r)
          {
           fact = fact * i; 
           i++;
          }
        sum=sum +fact;
        temp = temp /10;
     }
     if(sum==n)
       printf("\n %d is a strong number \n",n);
   }
}

output:


PROGRAM TO FIND WHETHER THE GIVEN NUMBER IS STRONG OR NOT

A NUMBER IS CALLED STRONG NUMBER IF SUM OF THE FACTORIAL OF ITS DIGIT IS EQUAL TO NUMBER ITSELF
FOR EXAMPLE: 145
I FACTORIAL IS 1
4 FACTORIAL IS 24
5 FACTORIAL IS 120
THEREFORE 1 + 24 +120 =  145 

PROGRAM:

 // prg to illustrate strong number

#include<stdio.h>

void main()
{
 int n,i,r,sum=0,temp,fact;
 printf("enter any number:");
 scanf("%d",&n);
 temp=n;
 while(n != 0)
  {
   i=1,fact=1;
   r=n %10;
   while(i <= r)
     {
      fact = fact * i;
      i++;
     }
     sum=sum +fact;
     n = n /10;
  }
  if(sum==temp)
    printf("%d is a strong number \n",temp);
  else
    printf("%d is not a strong number \n",temp);
}

output:


ARMSTRONG NUMBERS IN BETWEEN MIN AND MAX VALUES

// prg to illustrate Armstrong numbers in between min and max values

#include<stdio.h>

void main()

{

 int min,max,n,r,arm=0,temp;

 printf("\n Enter min value :");

 scanf("%d",&min);

 printf("\n Enter max value :");

 scanf("%d",&max);

 printf("\n Armstrong number in the given range :");

 for(n=min ; n<=max ; n++)
 
  {
 
   temp=n,arm=0;

   while(temp != 0)

     {

      r = temp % 10;

      temp = temp / 10;

      arm = arm + (r * r * r);

     }

     if( n == arm )

       printf("\n%d  is an armstrong  \n",n);

  }

}  

output:


PROGRAM TO FIND WHETHER THE GIVEN NUMBER IS ARMSTRONG OR NOT

THOSE NUMBERS WHOSE SUM OF ITS DIGITS TO POWER OF NUMBER OF ITS DIGITS IS EQUAL TO THAT NUMBER ARE KNOWN AS ARMSTRONG NUMBER
FOR EXAMPLE: 153
TOTAL DIGITS IN 153 IS 3 
THEREFORE = 1^3 + 5^3 +3^3
                       =    1   +  125  + 27
                       = 153                    


FOR EXAMPLE: 1634
TOTAL DIGITS IN 1634 IS 4
THEREFORE = 1^4  +  6^4  + 3^4  + 4^4
                       =    1   +  1296   + 81   + 64
                       = 1634                   

// prg to illustrate given number is Armstrong or not


#include<stdio.h>
void main()
{
 printf("enter any number:");

 int n,r,arm=0,temp;


 scanf("%d",&n);

 temp=n;

 while(n != 0)

  {

   r = n % 10;

   n = n / 10;

   arm=arm + (r * r * r);

  }

  if( temp == arm )

   printf("%d  is an armstrong  \n",temp);

  else

   printf("%d  is not a armstrong \n",temp);

}  

OUTPUT:

 

Friday, 1 February 2019

PROGRAM TO FIND FACTORIAL OF A GIVEN NUMBER

PROGRAM TO ILLUSTRATE FACTORIAL OF A GIVEN NUMBER

// prg to illustrate factorial of a  given number 
#include<stdio.h>
void main()
{
 int n,fact=1,num;
 printf("enter any number:");
 scanf("%d",&n);
 num=n;
 while(n != 0)
   {
   fact = fact * n;  
   n--;
  }
  printf("%d factorial is %d \n",num,fact);
} 

output:

Programs in turboc3 : Files

File Handling in C File Handling concept in C language is used for store a data permanently in computer. Using this concept we can store our...