Problem:
A 3-digit number such that square of sum of the first,second and twice the third digit is equal to the same number. find that number?
Code:
import java.lang.*;
class Number1
{
public static void main(String[] args)
{
int a,b,c,d,e,f,g;
clrscr();
//let us consider a for loop from 100 to 1000 because its a 3-digit number
for(a=100;a<1000;a++)
{
b=a%10;//last digit will comes i.e.,, if xyz is 3-digit number then z will comes
c=a/10;;//first 2 digits will comes i.e.,, if xyz is 3-digit number then xy will comes
d=c%10;//by doing this we get middle digit ie,, y
e=a/100;//we get first digit i.e,, x
//caluclatethe sum of 1st,2nd and twice the third digit
f=2*b+d+e;
//caluclate square of resultant
g=f*f; //sum of squares of 1st and second digits i.e., (x*x)+(y*y)
if(a==g)
{
System.out.println("The answer for the problem is"+a);
}
}
}
}
A 3-digit number such that square of sum of the first,second and twice the third digit is equal to the same number. find that number?
Code:
import java.lang.*;
class Number1
{
public static void main(String[] args)
{
int a,b,c,d,e,f,g;
clrscr();
//let us consider a for loop from 100 to 1000 because its a 3-digit number
for(a=100;a<1000;a++)
{
b=a%10;//last digit will comes i.e.,, if xyz is 3-digit number then z will comes
c=a/10;;//first 2 digits will comes i.e.,, if xyz is 3-digit number then xy will comes
d=c%10;//by doing this we get middle digit ie,, y
e=a/100;//we get first digit i.e,, x
//caluclatethe sum of 1st,2nd and twice the third digit
f=2*b+d+e;
//caluclate square of resultant
g=f*f; //sum of squares of 1st and second digits i.e., (x*x)+(y*y)
if(a==g)
{
System.out.println("The answer for the problem is"+a);
}
}
}
}
No comments:
Post a Comment