What is Weak Arm number
Weak arm numbers are those where the number is
equal to the sum of the digits to the power
'n'. 'n' is the number of digits in the number and it is maximum for the unit
digit value and decreases by one
For example
to check whether 153 is an Weak Arm number, the sum would be like 1 1
+ 5 2 + 3 3. 153 is not weak arm number. Examples of weak
arm numbers are 89, 135, 175, 518, 598
import java.io.*;
public class WA
{
void showWeakArm() throws Exception
{
int c=0;
int a,d,b,n;
double
sum=0;
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.println("enter the no.");
n=Integer.parseInt(br.readLine());
b=n;
while(b >0)
{
c++;
b=b/10;
}
b=n;
while(b >0)
{
a=b%10;
sum=sum+Math.pow(a,c);
b/=10;
c--;
}
if(n==(int)sum)
System.out.println(n+ " is A WeakArm
Number");
else
System.out.println(n+ " is Not A WeakArm
Number");
}
public static void main(String args[]) throws
Exception
{
WA ob=new WA();
ob.showWeakArm();
}
Using C :
ReplyDelete#include
#include
#include
int main()
{
int n,i,count,r, a[100],s=0,temp,power;
printf("Enter the number:");
scanf("%d",&n);
temp=n;
count = log10(n)+1;
power=count;
for(i=0;i<count;i++)
{
r=n%10;
a[i]=r;
n=n/10;
printf("\na[%d] = %d",i,a[i]);
}
for(i=0;i<count;i++)
{
s=s+round(pow(a[i],power));
power--;
}
if(temp==s)
printf("\nWeak Arm Number");
else
printf("\nNot Weak Arm Number");
}
Very helpful and logically done๐๐
ReplyDeletetwas very helpful thanks!
DeleteWelcome. Sorry for the late
DeleteThanks again for your help
ReplyDeleteWelcome
DeleteNice
ReplyDeleteYour program is wrong because you have not inasilized the variable sum .So it's a wrong program first check and then write an program
ReplyDeleteNot clear Dear, please check both (your comment and the program)
Delete