2007 Aug 07 11:30 AM
Hi,
How to write a program.
1. Accept a number and display whethere it is a amstrong number or not.
Thanks
2007 Aug 07 11:52 AM
*34) Write a program to find the sum & product of the first N
*Armstrong numbers. The user should enter a value for N. (Word of
*caution: See that the user should not enter a value for N which is
*more than 5).
PARAMETERS:
P_INPUT TYPE I.
DATA:
W_COUNT TYPE I,
W_INTVALUE TYPE I,
W_TEMP TYPE I,
W_QUO TYPE I,
W_RESULT(10) TYPE N VALUE 0,
W_PRODUCT(10) TYPE N VALUE 1,
W_SUM(10) TYPE N VALUE 0.
IF P_INPUT GT 5.
WRITE:
'Donot Enter Number > 5'(003).
ELSE.
WHILE W_COUNT LE P_INPUT.
ADD 1 TO W_INTVALUE.
W_TEMP = W_INTVALUE.
W_RESULT = 0.
WHILE W_TEMP > 0.
W_QUO = W_TEMP MOD 10.
W_RESULT = W_RESULT + W_QUO * W_QUO * W_QUO.
W_TEMP = W_TEMP DIV 10.
ENDWHILE.
IF W_RESULT = W_INTVALUE.
W_COUNT = W_COUNT + 1.
W_SUM = W_SUM + W_RESULT.
W_PRODUCT = W_PRODUCT * W_RESULT.
ENDIF.
W_INTVALUE = W_INTVALUE + 1.
ENDWHILE.
ENDIF.
WRITE:
/ 'Sum of the Armstrong Numbers '(001),W_SUM,
/ 'Product of the Armstrong Numbers '(002),W_PRODUCT.
Regards,
Pavan
2007 Aug 07 11:51 AM
Hi Rams
Check the below code snippet.
parameters : num type numc3.
data : sum type i.
sum = num(1) ** 3 + num+1(1) ** 3 + num+2(1) ** 1.
if num = sum.
write : ' Armstrong Number'.
else.
write : 'Not a good one!'.
endif.
Reward points if helpful!!
~Ranganath
2007 Aug 07 11:53 AM
Hi Rams
Just a little mistake in the previous one.
Check this.
Check the below code snippet.
parameters : num type numc3.
data : sum type i.
sum = num(1) ** 3 + num+1(1) ** 3 + num+2(1) ** 3.
if num = sum.
write : ' Armstrong Number'.
else.
write : 'Not a good one!'.
endif.
Reward points if helpful!!
~Ranganath
2007 Aug 07 11:52 AM
*34) Write a program to find the sum & product of the first N
*Armstrong numbers. The user should enter a value for N. (Word of
*caution: See that the user should not enter a value for N which is
*more than 5).
PARAMETERS:
P_INPUT TYPE I.
DATA:
W_COUNT TYPE I,
W_INTVALUE TYPE I,
W_TEMP TYPE I,
W_QUO TYPE I,
W_RESULT(10) TYPE N VALUE 0,
W_PRODUCT(10) TYPE N VALUE 1,
W_SUM(10) TYPE N VALUE 0.
IF P_INPUT GT 5.
WRITE:
'Donot Enter Number > 5'(003).
ELSE.
WHILE W_COUNT LE P_INPUT.
ADD 1 TO W_INTVALUE.
W_TEMP = W_INTVALUE.
W_RESULT = 0.
WHILE W_TEMP > 0.
W_QUO = W_TEMP MOD 10.
W_RESULT = W_RESULT + W_QUO * W_QUO * W_QUO.
W_TEMP = W_TEMP DIV 10.
ENDWHILE.
IF W_RESULT = W_INTVALUE.
W_COUNT = W_COUNT + 1.
W_SUM = W_SUM + W_RESULT.
W_PRODUCT = W_PRODUCT * W_RESULT.
ENDIF.
W_INTVALUE = W_INTVALUE + 1.
ENDWHILE.
ENDIF.
WRITE:
/ 'Sum of the Armstrong Numbers '(001),W_SUM,
/ 'Product of the Armstrong Numbers '(002),W_PRODUCT.
Regards,
Pavan
2007 Aug 07 12:03 PM
Hi Ram,
parameters : NO(5) type N
data : sum type i,
v_length type i,
v_number type i,
c_three type i value '3'.
v_length = length( NO ).
do v_length times.
v_number = v_length+sy-index(1).
v_number = v_numbr ** c_three.
sum = sum + v_number.
clear v_number.
enddo.
if NO = sum.
write : ' Armstrong Number'.
else.
write : 'Not a good one!'.
endif.
Thanks,
Vinay
2007 Aug 07 12:18 PM
Hi,
check out the below program it might help you
REPORT ZVENKI.
parameters : enter type numc3.
enter is the value which you enter at run time.
data : sum type i.
sum is an variable which will store the result of your calculation.
sum = enter(1) ** 3 + enter+1(1) ** 3 + enter+2(1) ** 3.
111 + 555 + 333 = 153.
153 = 153.
if enter = sum.
if entered number is evaul to calculated number then its an armstrong number.
write : ' Armstrong Number'.
153 is an armstrong number
else.
write : 'Not an armstrong number'.
*othe number is not an armstrong number
endif.
**********please reward points if the information is helpful to you***************
2007 Aug 07 12:48 PM
Program to find all amstron numbers
REPORT z_amstron.
DATA : num TYPE numc4.
DATA : COUNT TYPE i VALUE 0.
DATA : sum TYPE i.
DO 10000 TIMES.
num = COUNT.
PERFORM get_ams.
COUNT = COUNT + 1.
ENDDO.
*&---------------------------------------------------------------------*
*& Form get_ams
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get_ams.
sum = num(1) ** 3 + num+1(1) ** 3 + num+2(1) ** 3 + num+3(1) ** 3.
IF num = sum.
WRITE : / num , ' is an Amstron number'.
ENDIF.
ENDFORM. "get_ams
2007 Aug 07 1:12 PM
hi,
hope it helps u.
parameter n type i.
data : s type i,
rem type i,
d type i .
s = n.
while n gt 0.
rem = n mod 10.
d = d + rem * rem * rem.
n = ( n ) div 10.
endwhile.
if s eq d.
write 'armstrong'.
else.
write 'not armstrong'.
endif.
please reward points.