Question: 1 . Write a recursive function to find the sum of the first n natural numbers. Example: For ( n = 5 )

1. Write a recursive function to find the sum of the first n natural numbers.
Example: For \( n=5\), the result should be \(1+2+3+4+5=15\).
2. Write a recursive function to count the number of digits in an integer.
Example: Input: 12345- Output: 5.
3. Write a recursive function to check if a given array is sorted in ascending order.
Example: Input: \([1,2,3,4]\rightarrow \) Output: true.
4. Write a recursive function to compute \( a^{b}\)(a raised to the power of b).
Example: Input: \( a=2, b=3\rightarrow \) Output: 8.
5. Write a recursive function to convert a binary number (given as a string) to its decimal equivalent.
Example: Input: "101"\(\rightarrow \) Output: 5.
6. Create a base class Shape with a method area(). Implement subclasses like Circle and Rectangle to override the area() method.
7. Multiply two matrices entered by the user.
8. Input student marks for 5 subjects and calculate the total, percentage, and grade using conditions. Work with arrays, loops, and conditions to process multiple inputs.
9. Check if a given string or number reads the same backward as forward. Manipulate strings and numbers, and use loops or recursion.
10. Check if a given number is prime or not.
11. Basic arithmetic calculator: Input two numbers and an operator \((+,-,/,*)\), then perform the operation and print the result.
12. Write a program to search for an element in an array.
13. Write a program to find the transpose of the given matrix.
14. Write a program to find the second largest element in a array.
15. Write a program to find if the character is a vowel or a consonant.
16. Write a program to calculate Electricity Bill Calculation.
Write a program to calculate Electricity Bill Calculation.
Input: Units =250
Output: Bills: 1050
100 units: 1.5/unit
100-200 units: 2.5/unit
200+ units: 3.5/unit
17. Check if a Year is Both Leap Year and Century Year. Input: 2000, Output: Leap and Century year.
18. Write a program to check check Divisibility by 2,3, and 5.
19. Write a program to round the number to the nearest integer using Math.
20. Calculate hypotenuse of right angle triangle, using Math.
1 . Write a recursive function to find the sum of

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!