Quizzes & Puzzles16 mins ago
F . A . O. T. T. T.
12 Answers
Computer program or computer code required to verify answers 1998 and 2016 to previous birthday question!!
Answers
Here's a shorter Fortran version: program age do i = 2025,1925,-1 n = i k = 0 do if(n == 0) exit j = mod(n,10) k = k + j n = n / 10 end do if(k == 2025 - i) print "(2i4)", i, k end do end program age It can be run here: https://www. tutorialspoi nt.com/compi le_fortran_o nline.php
08:59 Sat 08th Jul 2023
Here's a Java version:
public class age{
public int sumDigits(int x)
{
String s = String.valueOf(x);
int sum = 0;
for(int i = 0; i1925; i--)
{
int age = 2025 - i;
int tot = sumDigits(i);
if(age == tot) System.out.println(String.valueOf(i)+" "+String.valueOf(age));
}
}
public static void main(String[] args){
new age();
}
}
If AB doesn't mess it up, it can be run here:
https:/ /www.pr ogramiz .com/ja va-prog ramming /online -compil er/
public class age{
public int sumDigits(int x)
{
String s = String.valueOf(x);
int sum = 0;
for(int i = 0; i1925; i--)
{
int age = 2025 - i;
int tot = sumDigits(i);
if(age == tot) System.out.println(String.valueOf(i)+" "+String.valueOf(age));
}
}
public static void main(String[] args){
new age();
}
}
If AB doesn't mess it up, it can be run here:
https:/
Here's another attempt:
public class age{
public int sumDigits(int x)
{
String s = String.valueOf(x);
int sum = 0;
int i =0;
while(i != s.length()){
sum += Integer.parseInt(String.valueOf(s.charAt(i)));
i++;
}
return sum;
}
age(){
int i = 2025;
while(i != 1925){
int age = 2025 - i;
int tot = sumDigits(i);
if(age == tot) System.out.println(String.valueOf(i)+" "+String.valueOf(age));
i--;
}
}
public static void main(String[] args){
new age();
}
}
https:/ /www.pr ogramiz .com/ja va-prog ramming /online -compil er/
public class age{
public int sumDigits(int x)
{
String s = String.valueOf(x);
int sum = 0;
int i =0;
while(i != s.length()){
sum += Integer.parseInt(String.valueOf(s.charAt(i)));
i++;
}
return sum;
}
age(){
int i = 2025;
while(i != 1925){
int age = 2025 - i;
int tot = sumDigits(i);
if(age == tot) System.out.println(String.valueOf(i)+" "+String.valueOf(age));
i--;
}
}
public static void main(String[] args){
new age();
}
}
https:/
Here's a shorter Fortran version:
program age
do i = 2025,1925,-1
n = i
k = 0
do
if(n == 0) exit
j = mod(n,10)
k = k + j
n = n / 10
end do
if(k == 2025 - i) print "(2i4)", i, k
end do
end program age
It can be run here:
https:/ /www.tu torials point.c om/comp ile_for tran_on line.ph p
program age
do i = 2025,1925,-1
n = i
k = 0
do
if(n == 0) exit
j = mod(n,10)
k = k + j
n = n / 10
end do
if(k == 2025 - i) print "(2i4)", i, k
end do
end program age
It can be run here:
https:/