Question: Write a program to find the sum of the first n
natural numbers.
Example Input:n = 5
Example Output:15
Solution:
Question: Write a program to find the factorial of a number n
.
Example Input:n = 4
Example Output:24
Question: Write a program to print the multiplication table of a number n
.
Example Input:n = 3
Example Output:
3 x 1 = 3
3 x 2 = 6
3 x 3 = 9
...
3 x 10 = 30
Question: Write a program to reverse a given string.
Example Input:s = "hello"
Example Output:olleh
Question: Write a program to count the number of digits in a number n
.
Example Input:n = 12345
Example Output:5
Question: Write a program to print the first n
terms of the Fibonacci sequence.
Example Input:n = 5
Example Output:0 1 1 2 3
Question: Write a program to find the sum of digits of a number n
.
Example Input:n = 123
Example Output:6
Question: Write a program to check if a given string is a palindrome.
Example Input:s = "racecar"
Example Output:True
Question: Write a program to find the largest number in a list.
Example Input:lst = [3, 1, 4, 1, 5, 9]
Example Output:9
Question: Write a program to find the second largest number in a list.
Example Input:lst = [3, 1, 4, 1, 5, 9]
Example Output:5
Question: Write a program to count the number of vowels in a given string.
Example Input:s = "hello"
Example Output:2
Question: Write a program to find the sum of even numbers from 1 to n
.
Example Input:n = 10
Example Output:30
Question: Write a program to count the number of words in a given string.
Example Input:s = "hello world"
Example Output:2