GoHacking.com: Ethical Hacking and Cyber Security
Home » C PROGRAMMING

C Program for Pigeon Breeding Problem

Submitted by on Thursday, 28 February 20088 Comments

The problem is as follows…
Initially I have a pair of adult pigeons (capable of breeding) which give rise to another young pair every month until it reaches the age of 5 years (60 months). But the young pair starts breeding only when it is 2 months old. Once the adult pigeon pair starts breeding it never stops untils the age of 5 years. Assume the age of initial adult pigeon is 2 months old. This program takes the no. of months as input and will calculate the total no. of pigeons over a given time (as given by the input).

This problem is framed, based on my own imagination and I call this problem as PIGEON BREEDING PROBLEM. Here is the code

#include<stdio.h>
#include<process.h>

struct node
{
int age;
struct node *link;
};

typedef struct node* NODE;

NODE getnode()
{
NODE x;
x=(NODE)malloc(sizeof(struct node));
if(x==NULL)
{
printf(“Out of memory\n”);
exit(1);
}
return x;
}

void main()
{
unsigned long int count=1;
unsigned int months,i;
NODE first=getnode();/*this is the intial adult pair*/
first->age=2; /*assume the age of initial adult pair as 2*/
first->link=NULL;
printf(“Enter the no. of months\n”);
scanf(“%u”,&months);
for(i=0;iage>=2)&&(temp->age<=60)) { NODE temp1=getnode(); temp->age+=1;
temp1->age=1;
temp1->link=first;
first=temp1;
temp=temp->link;
++count;
}
else
{
temp->age+=1;
temp=temp->link;
}
}
}
printf(“Total no. of pairs after %u months=%ld\n”,months,count);
}



By using/following this site you agree to our Legal Disclaimer

8 Comments »

  • Beautiful Minds - Dell issue said:

    Thanks for sharing your thoughts in my blog about the Inspiron 1525 dell issue.. :)

  • Shank said:

    Nice site!! keep up the gud work.

  • Srikanth (author) said:

    Thanks for your support

  • mrinal said:

    thinking out of the box..nice effort..!!

  • Siddhant said:

    Ya ofcourse…it’s something very unusual and different…i like it…:-)

  • Arun said:

    its nice…….

    can you posted some small tricky program

  • Rupam said:

    i’ve liked all ur posts. It helps me a lot. I’m only 16 but a great fan of urs srikant

  • himanshu said:

    hey shrikant !!!!!
    i hav liked all your posts and also try them they works.
    but i have a problem when compiling “restart your pc on every startup” i m using tc compiler the problem is that whenever i execute the program it shows a error “PROGRAM TOO BIG TO FIT IN MEMORY”how this error can be removed.

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.