Archive for September, 2011

The program posted by mayur can be simplified further..

His program calculates n!,(n-r)! and r!.then it does further multiplication and division

If you observe the term n!/(n-r)! it can be written as n(n-1)..(n-r+1)(n-r)!/(n-r)! which reduces to n(n-1)..(n-r+1)

thus if we calculate the above term , calculate r! and divide above term by r! we will have the answer in little less calculations!!

Here is the C  program for it…..

 

#include<stdio.h>
float nCr(int n,int r)
{
 int num=1,den=1,i;

 for(i=1;i<=r;i++) //calculates r!
  den*=i;

 for(i=n;i>=n-r+1;i--)  //calculates n(n-1)..(n-r+1)
  num*=i;

 return (float)num/(float)den;//returns n(n-1)..(n-r+1)/r!=nCr

}
void main()
{
 int n,r;
 clrscr();
 printf("Enter value of n and r for nCr computation");
 scanf("%d%d",&n,&r);
 printf("\nThe value of %dC%d is %f",n,r,nCr(n,r));
 getch();
}

Here is a short and sweet code to find maximum of three numbers input by the user…

 

It checks whether a>b if so then it goes into true condition part and checks for a>c, if this is true it returns’ a ‘as the answer,if not then c>=a and as a>b already , it returns false condition part i.e. ‘c’ as the answer.

Now, if initial condition (a>b)is false it means that b>=a it checks for false condition part i.e whether b>c. If this is true then obviously’ b’ is returned as greater value(true condition part),else it means that  c>=b and as already b>=a ,it returns false condition part i.e b as the answer.

 

May seem to be little complicated at first look,but it’s not so!

#include<stdio.h>
void main()
{
	int a,b,c,max;

        printf("Enter any three nos.");
	scanf("%d %d %d",&a,&b,&c);
	max=(a>b?(a>c?a:c):(b>c?b:c));//use of conditional operators
	printf("The greatest no is %d",max);

}

How to enable your facebook timeline

Posted: September 26, 2011 by Mayur More in TechnoCraft

How to enable your facebook timeline.

Program to generate Pythagoras triplets

Posted: September 25, 2011 by nikhilsambhus in Catchy codes
The following program will accept 'n' from user and display pythagoras triplets between 1 and 'n'

#include<stdio.h>
void main()
{
 int a,b,c,n;
 clrscr();
 printf("Enter any integer");
 scanf("%d",&n);
 printf("Pythagoras triplets between 1 & %d are\n",n);

 for(c=1;c<=n;c++)          //hypotenuse
  {
   for(a=1;a<=n;a++)        //smaller side
    {
     for(b=a;b<=n;b++)      //larger side
      {
       if(a*a+b*b==c*c)
       {
	printf("\n%d,%d,%d",a,b,c);
	break;
       }
      }
    }

   }
 getch();
}

How to enable your facebook timeline

Posted: September 24, 2011 by Mayur More in TechnoCraft

 

Announced yestarday at the f8 conference is a completely new redesign of Facebook; this new design is more customizable to your needs and filters out a lot of the trash that can build up over time and ruin the quality of your Facebook experience. If you’re an impatient person like me and you want to access the new Facebook Timeline layout, follow these simple steps to activate it.

Once you’ve logged into your Facebook account, enable Developer mode.

To do this, go to the search bar and type Developer. You’re looking for an application made by Facebook — it should be the first result that appears. Once you click on it, give it permission for your account.

How to Enable Facebook Timeline

If it doesn’t automatically get you to a screen that looks like what you see above, head over to the Developer section of Facebook and create a new application.

This application will not be seen by anybody, but it is needed to activate Facebook Timeline. Once you name your application, you must agree to the platform privacy agreement.

Once your application has been created, head to the Settings page in the Developer application. Under the settings for your application, look for where it says Open Graph and click on the Get Started Using Open Graph link.

Once you click that link, there will be a form where you may enter test actions. In these two fields you may enter whatever you wish, as long as it goes along the lines with the statement.

How to Enable Facebook Timeline

Once you press the Get Started button, you should be thrown into a configuration prompt and you may change data and save it again.

Now it’s time to wait (not long — only five minutes or so) and head back to your main Facebook profile.

On the top you should see your invitation to the Facebook Timeline beta. Presto! You’re in!

Have fun with the new Timeline and tell us what you think about it. Is this the last time Facebook will make a major change, or will it happen again soon?

TOWER OF HANOI

Posted: September 20, 2011 by Mayur More in Catchy codes

TOWER OF HANOI:

HOW TO SOLVE:

RECURSIVE  SOLUTION CODE:

The famous Towers of Hanoi problem has an elegant solution through recursion. In the problem, three pegs, A, B and C exist. ‘n’ disks of differing diameters are placed on peg A so that the larger disk is always below a smaller disk. The objective is to move all the disks to peg C using peg B as auxiliary. Only the top disk on any peg may be moved to any other peg, and the larger disk may never rest on a smaller one.

The famous Towers of Hanoi problem has an elegant solution through recursion. In the problem, three pegs, A, B and C exist. ‘n’ disks of differing diameters are placed on peg A so that the larger disk is always below a smaller disk. The objective is to move all the disks to peg C using peg B as auxiliary. Only the top disk on any peg may be moved to any other peg, and the larger disk may never rest on a smaller one.

Programming Geeks : Towers of Hanoi

The recursive solution involves the following steps :

1. if n==1, move the single disk from A to C and stop.

2. Move the top n-1 disks from A to B, using C as auxiliary.

3. Move the remaining disk from A to C.

4. Move the n-1 disks from B to C, using C as auxiliary.

The exe file for the C code of this problem can be downloaded from here :TOWERS.

The C code is presented below :

#include "stdio.h"

void towers(int,char,char,char);

void towers(int n,char frompeg,char topeg,char auxpeg)
	{ /* If only 1 disk, make the move and return */
	  if(n==1)
	    { printf("\nMove disk 1 from peg %c to peg %c",frompeg,topeg);
	      return;
	    }
	  /* Move top n-1 disks from A to B, using C as auxiliary */
	  towers(n-1,frompeg,auxpeg,topeg);
	  /* Move remaining disks from A to C */
	  printf("\nMove disk %d from peg %c to peg %c",n,frompeg,topeg);
	  /* Move n-1 disks from B to C using A as auxiliary */
	  towers(n-1,auxpeg,topeg,frompeg);
	}
main()
	{ int n;
	  printf("Enter the number of disks : ");
	  scanf("%d",&n);
	  printf("The Tower of Hanoi involves the moves :\n\n");
	  towers(n,'A','C','B');
	  return 0;
	}

Pascal’s Triangle

Posted: September 20, 2011 by Mayur More in Printing Pyramids


 

 

 

 

 

 

CLICK TO KNOW MORE ABOUT PASCAL’S TRIANGLE:

 

CODE:

#include<stdio.h>
#include<conio.h>
#include<math.h>
 
long factorial(int);
 
main()
{
   int i, n, c,k;
 
   printf("Enter the number of rows you wish to see in pascal triangle\n");
   scanf("%d",&n);
   k=n;
 
   for ( i = 0 ; i < n ; i++ )
   {
      for ( c = 0 ; c<=k-2  ; c++ )
	 printf(" ");
	 printf("%d",c);

      for( c = 0 ; c <= i ; c++ )
         printf("%ld ",factorial(i)/(factorial(c)*factorial(i-c)));
 
      printf("\n");
      k--;
   }
 
   getch();
   return 0;
}
 
long factorial(int n)
{
   int c;
   long result = 1;
 
   for( c = 1 ; c <= n ; c++ )
         result = result*c;
 
   return ( result );
}

 

Video Tutors

Posted: September 11, 2011 by Mayur More in Uncategorized

Now learn  and understand through videos on our VIDEO TUTOR: