Question

In: Computer Science

Write a PL/SQL program that prints following: if sum of its digits raised to the power...

Write a PL/SQL program that prints following: if sum of its digits raised to the power n is equal to number itself, where n is total digits in number.

If the Input is: 129, then output of the program will be: 738

Solutions

Expert Solution

Hi,

By the question I understood that you are looking for Armstrong numer check.

Below is the code which takes user input and prints the sum of the digits to the power of the number of digits and it also prints if the given number is Armstrong number or not

declare
    n number;
    s number:=0;
    r number;
    len number;
    m number;
 
begin
    n := &input;
 
   m := n; 
  
    len := length(to_char(n)); 
      
    -- while loop till n>0 
    while n>0 
    loop 
        r := mod(n , 10); 
        s := s + power(r , len); 
        n := trunc(n / 10); 
    end loop; 
    dbms_output.put_line('output is : ' || s);
    
    if m = s 
    then
        dbms_output.put_line('Armstrong number'); 
    else
        dbms_output.put_line('Not armstrong number'); 
    end if; 
      
end;

Below are the screeenshots:

The above program will ask for the input number.


Related Solutions

PL/SQL Write a PL/SQL block, using a Case Statement that prints a student’s letter     grade...
PL/SQL Write a PL/SQL block, using a Case Statement that prints a student’s letter     grade based on the value stored in a variable called grade. Use the ACC      grading system described in the course syllabus to create the block and set     the initial value of grade as 95. Use only one print statement and no      logical operators in your code. Assume a grade can exceed 100, but it      can’t be negative. Grade Scale: Grade Scale:...
PL/SQL Write a PL/SQL block, using a While Loop, to calculate and print the sum of...
PL/SQL Write a PL/SQL block, using a While Loop, to calculate and print the sum of the odd integers from 10 to 120 inclusive. (Hint: 11 + 13 + 15 + . . . + 97 + 99)
An Armstrong number is a number that is the sum of its own digits, each raised...
An Armstrong number is a number that is the sum of its own digits, each raised to the power of the number of its digits. For example, 153 is considered an Armstrong number because 13 + 53 + 33 = 153. Write a VBA program that lists all 3-digit Armstrong numbers within a specified range of 3-digit positive integers. Your sub should do the following: 1) Using two input boxes, ask the user to input two 3-digit positive integers (a...
Write a program that prints the sum of its command-line arguments (assuming they are numbers). For...
Write a program that prints the sum of its command-line arguments (assuming they are numbers). For example, java Adder 3 2.5 -4.1 should print The sum is 1.4
in .java Write a program that reads an integer with 3 digits and prints each digit...
in .java Write a program that reads an integer with 3 digits and prints each digit per line in reverse order. Hint: consider what you get from these operations: 319%10, 319/10, 31%10, ... Enter an integer of exactly 3 digits(e.g. 538): 319 9 1 3 Hint: consider what you get from these operations: 319%10 319/10 31%10
Please write an anonymous PL/SQL program which uses an implicit cursor to print out the score...
Please write an anonymous PL/SQL program which uses an implicit cursor to print out the score and rank of team 'Mad Scientists' in the competition 'Science Olympiad Regional Baltimore'. Please handle exceptions. Problem 4: [15 points] Please write an anonymous PL/SQL program to print out the names of students and their school names for the team that won the first place (rank=1) in Science Olympiad Maryland State (name of a competition). drop table school cascade constraints; drop table student cascade...
4. Write a program to compute the sum of digits of an integer. For example, given...
4. Write a program to compute the sum of digits of an integer. For example, given the integer 35931, your program should output 21. (21 is the sum 3 + 5 + 9 + 3 + 1) PYTHON
​Write a program which requests two weights in kilograms and grams and prints the sum of...
​Write a program which requests two weights in kilograms and grams and prints the sum of the weights. For example, if the weights are 3kg 500g and 4kg 700g, your program should print 8kg 200g. in c programming selection logic
Write a Python program that reads an integer and prints how many digits the number has,...
Write a Python program that reads an integer and prints how many digits the number has, by checking whether the number is ≥10,≥100,≥1000, and so on (up to 1,000,000). Your program should also identify if a number is negative.
Write a c program that prints the final sum of all values from 1 to n...
Write a c program that prints the final sum of all values from 1 to n only when n is a positive value. The program is to print "Poor!" when the final sum is less than 70, print "Good" when the sum is between 71 and 90. or "Great!" when the sum is 91 or better.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT