title | subtitle |
---|---|
Looping Practice |
Practice Code 3 |
This Notebook Contains practice question for the note on Looping Statements.
Try working online at:
Coding Ground - Tutorials Point
Online Compiler and Debugger
Q1: Write a program to get the value of n from the user and print sum of n natural numbers as output.
Q2: Write a program to get the values of n and n numbers from the user and print sum of the n numbers as output.
Input:
First line contains the number n
Next n lines contain n integers
Output: Sum of n numbers
Sample 1:
I/P:
10
1
5
7
22
20
40
2
53
18
-1
O/p: 167
Q3: Write a program get a number from user and print if it is prime or composite.
Q4: Write a program to get a number from the user and print its factorial as output.
Q5: Write a program to get the value of n from the user and print the first n terms of the Fibonacci series as output.
Q6: Write a program to get a number n from the user and print its reverse as output.
Q7: Write a program to get a number and check if it is an armstrong number or not.
Condition: Armstrong / Narcissistic number is the number in any given number base, which forms the total of the same number, when each of its digits is raised to the power of the number of digits in the number.
Sample 1:
I/P: 153
O/P: Armstrong Number
Explanation: $ 1^3 + 5^3 + 3^3 = 153 $
>**Sample 2:** I/P: 407 O/P: Armstrong Number **Explanation:** $ 4^3 + 0^3 + 7^3 = 407 $
>**Sample 3:** I/P: 107 O/P: Not an Armstrong Number
Q8: Write a program to get a number n and print its multiplication table from 1 to 20.
Q9: Write a program to get the values of n and n numbers from the user and print average of the n numbers rounded off to 4 decimal places as output.
Input:
First line contains the number n
Next n lines contain n integers
Output:
Average of n numbers
Sample 1:
I/P:
10
1
5
7
22
20
40
2
53
18
-1
O/p: 16.7
Q10: Write a program to get a number n and print the nth term of Fibonacci series as output.
Q11: Write a program to get two numbers as input and print their HCF as output.
Q12: Write a program to get two numbers as input and print their LCM as output.