Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

WEEK 4 PPS

Q1) Aim: To write a program to find the sum of digits of a given number using a while loop.

N=123, sum: 1+2+3=6

Description:

Firstly, we need to input variable integer and then we need write, while loop condition for variable
integer, to get sum of the digits, then we display output.

Algorithm:

Step 1: enter the variable integer.

Step 2: scan the integer.

Step 3: using the while loop for displaying the sum of digits in the integer.

Step 4: print the sum of digits.

Step 5: run the program.

Source code:

Output:

Q2) Aim: To WAP to display the multiplication table of any number using for loop.
Description:

Firstly we need to input variable integer and then we need write ,if loop condition for variable
integer, to get multiplied with natural numbers, then we display output, and we mention the limit of
natural number that need to be multiplied with the variable integer.

Algorithm:

Step 1: enter the variable integer.

Step 2: scan the integer.

Step 3: using the if loop for displaying the multiplication with natural numbers.

Step 4: print the multiplication table.

Step 5: run the program.

Source code:

Output:
Q3) Aim: To Write a program to check whether the given number is perfect or not using a while
loop.

Description:

here we need to input a variable number and scan the entered number. write a while loop for a
number, in-order to avoid it-self as a factor, by giving greater than or less than condition , then
giving if condition for checking weather a given number is factor or not, then adding all the factors if
we get the same number as the same we entered then the number is a perfect number or else it will
be not a perfect number.

Algorithm:

Step 1: enter the variable integer.

Step 2: scan the integer.

Step 3: using the while loop check for a number less than the entered number from considering as a
factor.

Step 4: using an if loop to check for the factors.

Step 5: then print the number is the perfect number if the sum of factors is equal to input number.

Step 6: else print the entered number is not a perfect number.

Step 7: run the program.

Source code:

Output:
Q4) Aim: To WAP and print the sum of first n natural numbers.

Description:

firstly we need to input a variable positive number such that, sum of natural numbers will be
continued till the entered variable number, and then displays the output and using for loop the
condition to be given for continuation of the sum and increment of initial value.

Algorithm:

Step 1: enter the variable positive number.

Step 2: scan the positive number.

Step 3: using the if loop, give the initialisation and update initial value.

Step 4: then print the number is the sum of natural numbers.

Step 5: run the program.

Source code:

Output:
Q5) Aim: To write a program for finding the factorial of a given number.

Description:

Here we need to input a variable positive integer for finding the factorial to the entered positive
integer then using a while loop, give a condition for the factorial and display the output.

Algorithm:

Step 1: enter the variable positive number.

Step 2: scan the positive number

Step 3: using the while loop, give the condition for factorial value.

Step 4: then print the factorial value of the entered number.

Step 5: run the program

Source code:

Output:

Q6) Aim: To write a program for checking whether the given 3-digit number is Armstrong or not.
(Armstrong number: the cube of every digit of a 3-digit number is the number itself.)

Description:

Firstly, we need to enter a variable integer, use while loop and if or else condition, need to know
whether the entered number is Armstrong or not.
Algorithm:

Step 1: enter the variable number.

Step 2: scan the number

Step 3: using the while loop, give the condition for Armstrong number.

Step 4: then print the number whether the entered number is Armstrong number or not of the
entered number.

Step 5: run the program

Source code:

Output:

Q7) Aim: To write a program to display Fibonacci series up-to ‘n’ terms.

Description:

Firstly, we need to input the variable number to give the Fibonacci number and give the suitable
condition and display the output.
Algorithm:

Step 1: enter the variable number

Step 2: scan the number

Step 3: using the while loop, give the condition for Fibonacci series.

Step 4: then print the Fibonacci series till the entered number.

Step 5: run the program.

Source code:

Output:

Q8) Aim: To WAP and print the even values from 1 to n.

Description:

Firstly, we need to enter a variable integer and scan the integer, using for loop condition and if
condition, so, the condition for even numbers need to display up-to entered value.

Algorithm:

Step 1: enter the variable number.


Step 2: scan the number

Step 3: using the for loop, give the condition for even numbers.

Step 4: then print the even number series till the entered number.

Step 5: run the program.

Source code:

Output:

Q9) Aim: To WAP and add the even and odd numbers from 1 to n.

Description:

Firstly, we need to enter a variable integer and scan the integer, using while loop condition and if
condition, so, the condition for even numbers and odd numbers summation need to display
separately up-to entered value.

Algorithm:

Step 1: enter the variable number.


Step 2: scan the number

Step 3: using the while loop, give the condition for even numbers and odd numbers.

Step 4: then print the even number and odd numbers series till the entered number.

Step 5: run the program.

Source code:

Output:

Q10) Aim: To WAP and check whether the number is prime or not.

Description:

firstly, we need to input a variable integer, then scan the integer, using for loop condition verify
whether the given number is prime or not, then display the output.

Algorithm:

Step 1: enter the variable number.

Step 2: scan the number

Step 3: using the for loop, give the condition for prime numbers.
Step 4: then print the condition for prime and non-prime numbers.

Step 5: run the program.

Source code:

Output:

You might also like