C Program for Pigeon Breeding Problem
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<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);
}
Related Posts
By using/following this site you agree to our Legal Disclaimer

Thanks for sharing your thoughts in my blog about the Inspiron 1525 dell issue..
Nice site!! keep up the gud work.
Thanks for your support
thinking out of the box..nice effort..!!
Ya ofcourse…it’s something very unusual and different…i like it…:-)
its nice…….
can you posted some small tricky program
i’ve liked all ur posts. It helps me a lot. I’m only 16 but a great fan of urs srikant
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!
I am the author and founder of GoHacking. You can read more about me or get in touch with me on Google+ or contact page.
EMAIL SECURITY »
What to Do When Your Email Account is Hacked?
How to Recover Hacked Email Accounts?
It can be a real nightmare if someone hacks and takes control of your email account as it may contain confidential information like bank logins, credit card details and other sensitive data. …
HOW STUFFS WORK »
How Antivirus Software Works
Due to ever increasing threat from virus and other malicious programs, almost every computer today comes with a pre-installed antivirus software on it. In fact, an antivirus has become one of the most essential software package for every computer. Even though every one …
HOW-TO GUIDES »
How to Retrieve Clipboard History in Windows
Ever copied a code snippet or text from the web and forgot to paste it before you copied something else? Well, all of us will have an experience of something like this, where we want to …
INTERNET SECURITY »
How to Hide Data in Image, Audio & Video Files: Steganography
Ever wondered to know how to hide secret messages in images, audio and video files? Well, in this post I will take you through a concept called steganography using which, it is possible to hide your secret information …
NETWORK HACKS »
Customize Google to Improve Search Results
Google is indisputedbly the best search engine out there on the Internet, however there are a few ways by which you can customize Google and make it even better. I have got 3 best free Firefox extensions using which you …
Categories
Most Popular
Most Commented
Blogroll
Log In | Entries (RSS) | Comments (RSS) | Sitemap
© 2008-2012 GoHacking.Com. This content is copyrighted to Srikanth and may not be reproduced on other websites.