Sunday 12 March 2017

Notice: Please Read


####################################################################

Hi Guys, 

It's been a long time since I have last posted. I had working a different and more versatile programming language "Python". If C is not language of Choice then there is a good news for you. I have started posting and sharing programs in much more organised way on my new blog about Python : allhailpython.blogspot.in. Please visit and give me your feedback. The blog will teach you everything from the scratch. Thanks for all the support, I got for this blog. I hope my new blog will also get same support.    

Take care :)

Tuesday 4 November 2014

Program for an output file in any format

In this program I would like to show you how to store your output file .
we can get output file in any format in order to use it for further use.



/* program for an output file */

#include<stdio.h>

int main()
{
  int i, j ;
  FILE *fp ;  //specific  pointer which stores data and transfer it to output file //

 fp= fopen("Output.xslx","w");

/* fopen creates a file if it is not already created otherwise overwrites it depends on the mode  .  " Output.xslx " is output file  name ,it could be anything and any format , "w" stands for writing mode in order to write into file , in order to read from file we use "r" */  

    for(i=0;i<=10;i++)
    {
       j=i+2;
      fprintf(fp, "%d  %d\n", i , j);

// fprintf is used to print output in the file ,just like normal printf with pointer's name //
          }

 fclose(fp);   // in order to close the file //
 return 0;

   }

Friday 17 October 2014

Finding the given number is a self number or not


Question - Finding the given number is a self number or not  .


Solution -


self number is an integer that cannot be written as the sum of any another integer n and the individual digits of n. This property is specific to the base used to represent the integers. 20 is a self number (in base 10), because no such combination can be found (all n < 15 give a result < 20; all other n give a result > 20). 21 is not, because it can be written as 15 + 1 + 5 using n = 15.


Source:Wikipedia 



Here is how we write code for this :->


/* programs tells whether input  no is self number or not  */

#include<stdio.h>
#include<stdio.h>
int main ()
{
int num,arr[10],k,j,i;
printf("Enter any number\n");
scanf("%d",&num);
div(num);
}
div(int z)
{
int i,p,k,j,a;

    for(i=0;i<z;i++)
    {
    a=i;
    p=0;
         while(a!=0)
        { 
        p=p+a%10;
        a=a/10;
        }     

            k=p+i;
            if(k==z)
         { 
        printf("Number is not the self number\nsince %d + %d =%d\n",i,p,z);
        break;
        }
        else
         {
        if(i==z-1)
        printf("It's a self number\n");
        }



    }


}



Monday 7 July 2014

Program for Palindrome prediction in C using strings

/*Hi guys,

I have a new program for finding Armstrong Numbers.Last program that i wrote was not properly generalized for all the numbers.Here is the new one,which can be used to find Armstrong Numbers for a longer range.
*/

#include<stdio.h>
int main()
{
   int i=1,g,a,num;
    while(i<500)
      {
        g=i;
        num=0;
    while(g>0)
      {
        a=g%10;
        num=num+a*a*a ;
        g/=10;
      }
    if(num==i)
        printf("%d\n",num);
        i++;

      }

  return 0;

}


This method is very efficient for longer rangers (i<=10000) , but since Armstrong Numbers can't be too big. it's doesn't help in finding more Armstrong numbers.There is caution ,which is supposed to be taken is that when we initialize num , it should be done before the second loop . initializing num before first loop or in the variables won't work and it will give you unexpected results.

Finding Armstrong Number Using loops



I have a new program for finding Armstrong Numbers.Last program that i wrote was not properly generalized for all the numbers.Here is the new one,which can be used to find Armstrong Numbers for a longer range.


#include<stdio.h>
int main()
{
   int i=1,g,a,num;
    while(i<500)
      {
        g=i;
        num=0;
    while(g>0)
      {
        a=g%10;
        num=num+a*a*a ;
        g/=10;
      }
    if(num==i)
        printf("%d\n",num);
        i++;

      }

  return 0;

}


This method is very efficient for longer rangers (i<=10000) , but since Armstrong Numbers can't be too big. it's doesn't help in finding more Armstrong numbers.There is caution ,which is supposed to be taken is that when we initialize num , it should be done before the second loop . initializing num before first loop or in the variables won't work and it will give you unexpected results.