Problem Statment: A person born in the 18th century was x years old in the year x2. Is there a corresponding puzzle for the 19th Century?
also show that there is no corresponding puzzle for the 20th Century.
Note: there is no user input for this program..this program should accomplish three goals and report results..
I am at a loss.. i know the person will be 42 in the year 1764 which makes him 54 in the year 1776, but i don't know what to do after this no do i know how to write the program for this...Please help!!
You could use a loop to check every age a person can have (say 1 to 150) and see if you can find a date in the 18th century that is exactly the square of that number.
The problem itself seems straightforward.
42*42 = 1764. This is 18th century solution. Person was born in 1722
43*43 = 1849. This is 19th century solution. Person was born 1806
44*44 = 1936. This is the only # which works for the 20th century.(next case 45*45 = 2025), but the person was born in 1936 - 44 = 1892 so no solution exists for the 20th century case, as expected.
Now, just write a program to work this out and report these findings.
@ne555
I think the problem requires that the person be born in the same century as his age squared.
The year 2025 is in the 21st century but 1980 is in the 20th century.
I may be misunderstanding the problem though. Heinz's problem statement was very brief and vague. I do feel like I'm guessing what the problem is.
I think fun2code is right. The interesting question would be, are there any more cases beyond 44 where this is true? (with a program, easy to determine; an analytical solution takes more thought)
If x is the age, x^2 will grow faster than x, so at some point the difference will be greater than 100 so there is no way the person will be born in the same century as his age squared.
No. 43 is not the last one. 44 didn't work, it's the failed 20th century case.
I think the #'s sought satisfy the following:
Let x = age. Then x*x is the year the person is age x. His birth year (Yb) is therefore:
Yb = present year - age = x*x - x = x*(x-1).
We are looking for x such that birthyear/100 == present year/100 ( relying on the modulus operation here)
ie: if( (x*(x-1))/100 == (x*x)/100 ) then x is a solution.
I wrote the 3 line program to run for the range of ages suggested by Galik ( 1 to 150 ) and found the following:
Age = 1 works! Birthyear = 0.
I count 28 cases working for the 1st millenium.
x = 33 brings us to the 2nd millenium with x^2 = 1089 and birthyear = 1056.
There is quite a gap after age 43. That is the last solution until age = x = 58 in the year 3364, born in 3306.
The last case is for x = 86 in the year 7396, birthyear = 7310.
Total # of cases = 47
EDIT: Duh! Could limit consideration to ages < 100 because a 100+ year old was certainly not born in the same century as when turning 100.
can anyone write a sample program that i could use as a model to write my own..
Nope.
You write a program and if you need help figuring out how to get it to work, post questions.
You should thank fun2code for the results already! What he has posted is more than half the battle.
(You can check your answers against his and if it doesn't match, you can look for bugs.)
"Heinz's problem statement was very brief and vague. I do feel like I'm guessing what the problem is."
I know it is very vague but that is what the teacher gave us. fun2code was right 42*42 =1764...then the person would be 54 in the yr 1776..that is the first goal.....the puzzle for 19 century is 43*43 =1849....1849-43=1806(here's the corresponding puzzle) the 20th century doen't work cuz 44*44=1936...1936-44=1892(it don't work)------the task is to write a program that shows this. does that make it clearer
i figuered out the numerical portion of the answer..now all i must do is write a program to show/prove all of what i said in the previous post...so no i have not found my answer yet u could say
I tried to give as many clues as I could without giving the solution outright.
It really is just 3 lines. Take the if-statement from my last post, put a for loop on top and a cout below and you get the output for every case. Use the if statement to build your solution around.
Heinz. Here is something that might work for you. This program lists all cases that work for the puzzle given. You may need to modify it to meet your assignments requirements. Check to be sure that it solves the problem you gave, in case I got it wrong. Good luck in your studies.
1 2 3 4 5 6 7 8 9 10 11
#include <iostream>
usingnamespace std;
int main()
{
for(int n=1; n<100; n++)// age = n, year = n*n
if( (n*(n-1))/100 == (n*n)/100 )// so birthyear = year - age = n*n - n = n*(n-1)
cout << "Age = " << n << " Year = " << n*n << " Birthyear = " << n*(n-1) << endl;
system("PAUSE");
return 0;
}
Thank you fun2code...i probly wouldn't be able to pass a test even if u didn't give me the answer straight up..i just don't get this stuff...but this class is a requirement so i am just gonna have to squeak by....i'll probly be back here to the wonderful world of the C++ forum... thank you for all ur help everyone!!
i have the same problem, and need some help. Could you guys look at my code I have so far and fix it or tell me how to fix it.
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int x,y,c,n,z,t,s;
cout <<"A person born in the 18th century was x years old in the year (x*x) \n";
cout <<"How old was the person in 1776? \n";
do
{ y=(x*x);
if ((y>1700) && (y<1800));
break; }
while ((x>1) && (x<100));
cout<< y <<endl;
cout <<"The same pattern can be seen in the 19th century \n";
cout <<"The pattern can not be seen in the 20th century \n";