Saturday, February 11, 2012

Algorithm (Lab report 01)

Theory: Counting is very essential for all of us. In the counting system we can count top to bottom (First to last), Bottom to top (Last to first) for solution of our counting problem. It also can be increment or decrement system.

P´olya’s counting theory provides a wonderful and almost magical method to solve a large variety of combinatory problems where the number of solutions is reduced because some of them are considered to be the same as others due to some symmetry of the problem.

We’ll begin with a few problems that are simple enough to solve without P´olya’s method, which we will do, and then we will simply apply the magic method, showing the technique, but without explaining why it works, and we’ll see that the same answer is obtained in both cases.

Apparatus:
            i.  Computer.
           ii.  Algorithm.
          iii.  Compiler (Code block, Dev c/c++, Turbo c/c++ etc.)
iv. 
Coding skill.
Algorithm: (Simplified algorithm with counting)
Step 01: Algorithm Add( M,N)
Step 02: {
Step 03: for(i=1 to M do)
Step 04:        {
Step 05:        count+=2;
Step 06         for(j=1 to N do)
Step 07:        count+=2;
Step 08:        }
Step 09: count+=1;
Step 10:}

Source code:
# include<stdio.h>
# include<conio.h>
int main()
{
clrscr();
int M,N,i,j,count=0;
printf("Enter first value: ");
scanf("%d",&M);
printf("Enter second value: ");
scanf("%d",&N);
for(i=1;i<=M;i++)
    {
    count+=2;
    for(j=1;j<=N;j++)
    count+=2;
    }
count+=1;
printf("Counting result of %d and %d is : %d",M,N,count);
getch();
return 0;
}
Result:
Sample input:                                 Sample output
Enter first value: 10
Enter second value: 12                 Counting result of 10 and 12 is : 161  
Enter first value: 1
Enter second value: 15                 Counting result of 1 and 15 is : 33    
Enter first value: 15
Enter second value: 1                   Counting result of 15 and 1 is : 61     

Caution: You must change this code. And also change the test value when you print it......Try to make change or modify this.