Sunday, February 26, 2012

Find amount in a Sentence.(Program)

***If anyone have any simple idea about this problem???
1. Your program will ask the user for an input (either float or double).
2. The user should enter a number within the following range i.e. from 0 to 999.99
3. The input represents an amount of money in taka and paisa.
4. Therefore, if the user enters an amount say 455.67, your program will print
                “Four Hundred and Fifty Five Taka and Sixty Seven Paisa”.


# include<stdio.h>
# include<conio.h>
unsigned long find_taka(unsigned long);
unsigned long find_paisa(unsigned long);
int main()
{
//clrscr();
unsigned long a,b;
char c;
printf("Enter Floating point amount: ");
scanf("%ld%c%ld",&a,&c,&b);
printf("\n\n");
find_taka(a);
if(a==0)
printf("Zero Taka ");
else
printf("Taka ");
find_paisa(b);
if(b==0)
printf("Zero Paisa ");
else
printf("Paisa.");
getch();
return 0;
}

unsigned long find_taka(unsigned long a)
{
unsigned long n;
if(a>=10000000)
    {
    n=a/10000000;
    find_paisa(n);
    printf("Crore ");
    a%=10000000;
    }
if(a>=100000)
    {
    n=a/100000;
    find_paisa(n);
    printf("Lakh ");
    a%=100000;
    }
if(a>=1000)
    {
    n=a/1000;
    find_paisa(n);
    printf("Thousand ");
    a%=1000;
    }
if(a>=100)
    {
    n=a/100;
    find_paisa(n);
    printf("Hundred ");
    a%=100;
    }
if(a<100)
find_paisa(a);
return 0;
}

unsigned long find_paisa(unsigned long n)
{
if(n>=1&&n<=19)
    {
    if(n==1)
    printf("One ");
    if(n==2)
    printf("Two ");
    if(n==3)
    printf("Three ");
    if(n==4)
    printf("Four ");
    if(n==5)
    printf("Five ");
    if(n==6)
    printf("Six ");
    if(n==7)
    printf("Seven ");
    if(n==8)
    printf("Eight ");
    if(n==9)
    printf("Nine ");
    if(n==10)
    printf("Ten ");
    if(n==11)
    printf("Eleven ");
    if(n==12)
    printf("Tweleve ");
    if(n==13)
    printf("Thirteen ");
    if(n==14)
    printf("Fourteen ");
    if(n==15)
    printf("Fifteen ");
    if(n==16)
    printf("Sixteen ");
    if(n==17)
    printf("Seventeen ");
    if(n==18)
    printf("Eighteen ");
    if(n==19)
    printf("Nineteen ");
    }
if(n>=20&&n<=29)
    {
    printf("twenty ");
    n%=20;
    find_paisa(n);
    }
if(n>=30&&n<=39)
    {
    printf("Thirty ");
    n%=30;
    find_paisa(n);
    }
if(n>=40&&n<=49)
    {
    printf("Fourty ");
    n%=40;
    find_paisa(n);
    }
if(n>=50&&n<=59)
    {
    printf("Fiftyty ");
    n%=50;
    find_paisa(n);
    }
if(n>=60&&n<=69)
    {
    printf("Sixtyty ");
    n%=60;
    find_paisa(n);
    }
if(n>=70&&n<=79)
    {
    printf("Seventyty ");
    n%=70;
    find_paisa(n);
    }
if(n>=80&&n<=89)
    {
    printf("Eighty ");
    n%=80;
    find_paisa(n);
    }
if(n>=90&&n<=99)
    {
    printf("Ninety ");
    n%=90;
    find_paisa(n);
    }
if(n>99)
printf("... ");
return n;
}

Friday, February 24, 2012

Algorithm (Lab report 03)

Theory: Insertion sort is a sorting algorithm with an O(n^2) running time. Although the worst case run time is the same as bubble sort, but it is a lot more applicable for smaller data sets. To understand this algorithm, it is very similar to how some people sort their hand of cards.
Here is how it works, we loop through the array. For each item in the array, the left side of the array is sorted and the right side is unsorted. We will take that item and put it in the appropriate spot then move on to the next item in the array.
Apparatus:
            i.   Computer.
           ii.   Coding Language.
          iii.   Compiler (Code block, Dev c/c++, Turbo c/c++ etc.)
          iv.    Coding skill.
Algorithm: ( Insertion sort)
Step 01: Algorithm for j to 2 to length[A]
Step 02: do key to A[j]
Step 03: Insert A[j] into the sorted sequence A[1….j-1]
Step 04: i to j-1
Step 05: while i>0 and A[i]>key
Step 06       do A[i+1] to A[i]
Step 07:          I to i-1
Step 08:      A[i+1] to key

Source code: (Insertion sort)
# include<stdio.h>
int main()
{
int A[20], N, Temp, i, j;      
scanf("%d", &N);
for(i=0; i<N; i++)
scanf("%d", &A[i]);
for(i=1; i<N; i++)
    {
    Temp = A[i];
    j = i-1;
    while(Temp<A[j] && j>=0)
        {
        A[j+1] = A[j];
        j = j-1;
        }
    A[j+1] = Temp;
    }
for(i=0; i<N; i++)
printf("%d ", A[i]);
return 0;
}


Result:
Sample Input                                           Sample output

5
5  4  1  2  3                                                1  2  3  4  5
7
1  4  2  5  6  1  7                                        1  1  2  4  5  6  7
8
2  3  6  5  34  11  12  15                          2  3  5  6  11  12  15  34


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

Saturday, February 18, 2012

Algorithm (Lab report 02)

Theory: Have you ever looked closely at a pinecone or a sunflower? Did you know that there are mathematical patterns in nature and in man-made objects as well?
A 13th Century mathematician, Leonardo of Pisa, nicknamed "Fibonacci", discovered a number pattern that was named after him, called the Fibonacci Sequence. You will be investigating the Fibonacci Sequence and patterns using the web resources below.
Apparatus:
           i.     Computer.
           ii.    Coding Language.
          iii.    Compiler (Code block, Dev c/c++, Turbo c/c++ etc.)
          iv.    Coding skill.
Algorithm: ( Fibonacci number generator) Iterative .
Step 01:  function fib(n : integer) return integer is
Step 01:   first  : integer := 0;
Step 01:   second : integer := 1;
Step 01:   tmp    : integer;
Step 01:   begin
Step 01:   for i in 1..n loop
Step 01:      tmp    := first + second;
Step 01:      first  := second;
Step 01:      second := tmp;
Step 01:   end loop;
Step 01:   return first;
Step 01:  end fib;

Source code: (Fibonacci number generator)
# include<stdio.h>
# include<conio.h>
void fibonacci(long);
int main()
{
clrscr();
long N;
scanf("%ld",&N);
fibonacci(N);
getch();
return 0;
}
void fibonacci(long N)
          {
          long i,f0=0,f1=1,f;
          for(i=0;i<N;i++)
                   {
                   f=f0+f1;
                   f1=f0;
                   f0=f;
                   printf("%3d",f1);
                   }
          }



OR
# include<stdio.h>
# include<conio.h>
int main()
{
clrscr();
long N, i,f0=0,f1=1,f;
scanf("%ld",&N);
for(i=0;i<N;i++)
                        {
                        f=f0+f1;
                        f1=f0;
                        f0=f;
                        printf("%3d",f1);
                        }
getch();
return 0;
}

Sample Input                                           Sample output

5                                                                0  1  1  2  3
8                                                                0  1  1  2  3  5  8  13
10                                                              0  1  1  2  3  5  8  13  21  34
3                                                                0  1  1

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

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.

Saturday, February 4, 2012

Triangular number

# include<stdio.h>
void triangular(long);
int main()
{
long N;
scanf("%ld",&N);
triangular(N);
return 0;
}
void triangular(long N)
{
long i,total=0;
for(i=1;i<=N;i++)
total=total+i;
printf("%d",total);
}

Finding Fibonacci number

# include<stdio.h>
void fibonacci(long);
int main()
{
long N;
scanf("%ld",&N);
fibonacci(N);
return 0;
}
void fibonacci(long N)
{
long i,f0=0,f1=1,f;
for(i=1;i<=N;i++)
{
f=f0+f1;
f1=f0;
f0=f;
printf("%3d",f);
}
}

Finding Prime number

# include<stdio.h>
# include<math.h>
long prime(long);
int main()
{
long N,i;
scanf("%ld",&N);
if(prime(N)!=0&&prime(N)!=1)
printf("%ld is a prime number",N);
else
printf("%ld is not a prime number",N);
return 0;
}

long prime(long N)
{
long j;
for(j=2;j<=(int)sqrt(N);j++)
if(N%j==0)
return 0;
return N;
}