Title: There are a pair of young rabbits, one months later into a small rabbit, rabbit one months later into a rabbit and gave birth to a pair of rabbits;
Q How many rabbits, rabbits, rabbits, and rabbits are there in a few years?
This month Bunny = Rabbit last month, this month's Bunny = Last month's bunny, this month rabbit = last month rabbit + last month rabbit.
int y = 1, x = 0, c = 0, i = 2;
Console.Write ("Please enter the year n=");
Double n = Double. Parse (Console.ReadLine ());
while (i <= * n)
{
c = c + x;x = Y;y = c;i++;
}
Console.WriteLine (n+ "Years later there is a total of" + (X+Y+C) + "only rabbits. One of the young rabbits "+y+" only, the small rabbit "+x+" only, Into the rabbit "+c+" only. ");
TITLE: Rooster 2 Cents A, hen 1 money A, chicken half text money, a total of only 100 money, how to gather enough 100 chickens in the case just spent 100 money?
All buy cocks can buy 50, all buy hens can buy 100, all buy chickens can buy 200;
Suppose bought a rooster x only (0<=x<=50), hen y only (0<=y<=100), Chick Z only (0<=z<=200);
Then there is 2x+y+0.5z=100, and x+y+z=100;
int sum=0;
for (int x = 0; x <= × x + +)
{
for (int y = 0; y <= 100;y++)
{
for (int z = 0; z <= 200;z++)
{
if (x + y + z = = && 2 * x + y + z/2 = = 100)
{
Console.WriteLine ("Can Buy: Rooster" + x + "only, hen" + y + "only, chick" + z + "only");
sum + = 1;
Console.WriteLine ("A total of" +sum+ "schemes");
}
}
}
}
Title: The best horse camel 2 stone grain, medium camel 1 stone grain, two pony 1 stone grain, to use 100 horses, camel 100 stone grain, how to allocate?
The whole use of the best horse needs 50 horses, the full use of the medium horse needs 100 horses, the whole use of the pony need 200 horses;
The horse was set up with S (0<=s<=50), the medium horse with Z (0<=z<=100), the pony with X (0<=x<=200);
So 2s+z+0.5x=100,s+z+x=100;
The program refers to the previous question, even the number has not changed;
Title: There are 1 cents, 2 cents, 5 cents coins, to be combined out of 2 cents, there are several combinations, how many each?
The idea is basically the same as the above two questions.
int sum = 0;
for (int x = 0; x <= 20;x++)
{
for (int y = 0; y <=; y++)
{
for (int z = 0; z <= 4; z++)
{
if (x+2*y+4*z==20)
{
Console.WriteLine ("Penny" + x+ "one, two cents" +y+ ", Five Cents" +z+ "a");
sum + = 1;
}
}
}
}
Console.WriteLine ("A total of" + sum + "kind of scheme!) ");
Title: The and of the number of prime numbers within 100;
A prime number can only be divided by 1 and its own, and a positive integer n, when n cannot be divisible by any integer of the open interval of "2,n-1", then N is prime.
Use for loop!
int sum = 0;
for (int i = 0; I <=; i++)
{
For (int j = 2; J <= I; j + +)
{
sum+=i;
if (i = = j)
{
console.write (i+ "\ t");
Break ;
}
else if (i% j = 0)
{
Sum-= i;
Break ;
}
Else
{
Sum-= i;
}
}
}
Console.WriteLine ();
Console.WriteLine ("Within 100 prime numbers and for:" +sum);
title: under ideal conditions, the height of the basketball free fall bounce is three-fourths of the last height, first the height is set to 1 meters, enter a number of times, to find the height of basketball now bounce?
The first time to play the basketball height is one meter, then the second bounce is 1* (3/4) meters, nth time is 1* (3/4) ^n meters;
Use the while statement!
Console.Write ("Please enter the number of n=");
int N=int. Parse (Console.ReadLine ());
Double m = 1;int i = 1;
while (I<n)
{
m = m * 3/4;
i++;
}
Console.WriteLine ("+n+" the height of the basketball ball is: "+m+");
Title: Odd and within 100;
The number that cannot be divisible by 2 is odd;
Using Do-while statements;
int sum=0,i=1;
Do
{
if (i% 2! = 0)
{
Console.Write (i + "t");
sum + = i;
}
i++;
}
while (i <= 100);
Console.WriteLine ("These odd-numbered and are:" +sum);
Fifth day Rest